Sunday, December 23, 2018

PROGRAM TO DISPLAY LINEAR SEARCH

/*PROGRAM  TO  DISPLAY  LINEAR  SEARCH*/

#include<stdio.h>
#include<conio.h>
void main()
{
   int array[100], search, c, n;
   clrscr();
   printf("Enter the number of elements in array\n");
   scanf("%d",&n);

   printf("Enter %d integer(s)\n", n);

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

   printf("Enter the number to search\n");
   scanf("%d", &search);

   for (c = 0; c < n; c++)
       {
      if (array[c] == search)     /* if required element found */
      {
         printf("%d is present at location %d.\n", search, c+1);
         break;
      }
   }
   if (c == n)
      printf("%d is not present in array.\n", search);

   getch();
}

OUTPUT:-
sk.

No comments:

Post a Comment

Wikipedia

Search results

Search The program