In this program, the user is asked to enter 10 elements in an array. After that user is ask for element that he/she wants to search in an Array. Then we search an element from starting to end until it is found. Finally, we display whether element is found or not on the screen.
#include <stdio.h>
#include<conio.h>
void main( )
{
int arr[10], search, i;
printf("Enter 10 numbers\n");
for (i = 0; i < 10; i++)
scanf("%d", &arr[i]);
printf("Enter a number to search\n");
scanf("%d", &search);
for (i = 0; i < 10; i++)
{
if (arr[i] == search) /* Check element is found */
{
printf("Number is found at location %d.", i+1);
break;
}
}
if (i == 10)
printf("Number is not found in the array.", search);
getch( );
}
Enter 10 numbers
4 3 7 2 9 6 5 1 8 10
Enter a number to search
5
Number is found at location 7.