Forget Code launches a powerful code generator for building API's

Linear search in C

linear search in c
Linear search in c programming: The following code implements linear search ( Searching algorithm ) which is used to find whether a given number is present in an array and if it is present then at what location it occurs.It is also known as sequential search. It is very simple and works as follows: We keep on comparing each element with the element to search until the desired element is found or list ends. Linear search in c language for multiple occurrences and using function.

   int array[100], search, c, number;
   printf("Enter the number of elements in array\n");
   printf("Enter %d numbers\n", number);
   for ( c = 0 ; c < number ; c++ )
   printf("Enter the number to search\n");
   for ( c = 0 ; c < number ; c++ )
      if ( array[c] == search )     /* if required element found */
         printf("%d is present at location %d.\n", search, c+1);
   if ( c == number )
      printf("%d is not present in array.\n", search);     
   return 0;