Linear search in C.

01  #include<stdio.h>
02 
03  int main()
04   {
05    int array[100], search, c, number; 
06    printf("Enter the number of elements in array\n");
07    scanf("%d",&number); 
08    printf("Enter %d numbers\n", number); 
09     
10    for ( c = 0 ; c < number ; c++ ) 
11    scanf("%d",&array[c]); 
12    printf("Enter the number to search\n");
13    scanf("%d",&search); 
14    
15    for ( c = 0 ; c < number ; c++ ) 
16     {
17      if ( array[c] == search )     /* if required element found */
18       {
19        printf("%d is present at location %d.\n", search, c+1); 
20     break; 
21       }
22     }
23    if ( c == number ) 
24     printf("%d is not present in array.\n", search);     
25     
26  return 0; 
27   }

 
 OUTPUT :
 
 (1st Run)
 
 Enter the number of elements in array
 5
 
 Enter 5 numbers
 12
 13
 14
 15
 16
 
 Enter the number to search
 14
 
 14 is present at location 3.
 
 (2nd Run)
 
 Enter the number of elements in array
 5
 
 Enter 5 numbers
 12
 13
 14
 15
 16
 
 Enter the number to search
 24
 
 24 is not present in array.