Pages

Write A Program Search A Given Number In Array Using Linear Search

Wednesday, 8 May 2013

#include <stdio.h>
#include <conio.h>
int main()
{
   int array[100], s, d, number;

   printf("Enter the number of elements in array: ");
   scanf("%d",&number);

   printf("Enter %d numbers: ", number);

   for ( d = 0 ; d < number ; d++ )
      scanf("%d",&array[d]);

   printf("Enter the number to search: ");
   scanf("%d",&s);

   for ( d = 0 ; d < number ; d++ )
   {
      if ( array[d] == s )  
      {
         printf("%d is present at location %d.", s, d+1);
break;
      }
   }
   if ( d == number )
      printf("%d is not present in array.", s);  

   getch();
}
 

Search Box

Most Reading

Contact Form

Name

Email *

Message *