Search a number using linear search - C

C program to read an array of 'n' numbers and also read a number to be searched. If search number is found then print its position.

Solution:

Linear search is also known sequential search. Following code checks if entered number is found in array or not  & print how many times it occurs in array.

#include <stdio.h>
int main()
{
      int a[50],i,n,c=0,sn;
      printf(" How many numbers you want to enter?: ");
      scanf("%d",&n);
      printf("\n Enter %d numbers: \n\n  ",n);
      for(i=0;i             scanf("%d",&a[i]);
      printf("Enter Number to be Searched : ");
      scanf("%d",&sn);
      for(i=0;i       {
            if(sn==a[i])
            {
                  printf("\nNumber '%d' Found at Position %d.",sn,i+1);
                  c=c+1;
            }
      }
      if(c==0)
      printf("\nNumber '%d'is Not Found.",n);
      return 0;
}


Output:

linear search