A C program that will search for elements in an array
- Nelson John
- Nov 26, 2017
- 1 min read

#include<stdio.h>
int main() {
int a[30], ele, num, i;
printf("\nEnter no of elements :");
scanf("%d", &num);
printf("\nEnter the values :");
for (i = 0; i < num; i++) {
scanf("%d", &a[i]);
}
//Read the element to be searched
printf("\nEnter the elements to be searched :");
scanf("%d", &ele);
//Search starts from the zeroth location
i = 0;
while (i < num && ele != a[i]) {
i++;
}
//If i < num then Match found
if (i < num) {
printf("Number found at the location = %d", i + 1);
} else {
printf("Number not found");
}
return (0);
}
Facebook: ayamnelrodinho1@gmail.com
Yahoo: talk2nelsonjohn2dat@yahoo.com
Whatsapp: +2349034595610
PLEASE KINDLY SHARE WITH FELLOW PROGRAMMERS AND ALSO SUBSCRIBE TO MY BLOG FROM THE HOME PAGE FOR MORE FEEDS.
Comentarios