Friday, June 15, 2018

IMPLEMENTATION OF LINEAR SEARCH IN C

SOURCE CODE:

#include<stdio.h>
#include<conio.h>
void main()
{
  int array[40], search, c, n;
  clrscr();
  printf("Enter the total number of elements in array\n");
  scanf("%d", &n);
  printf("Enter %d integer\n", n);
  for (c=0;c<n;c++)
   scanf("%d",&array[c]);
  printf("Enter a number to search\n");
  scanf("%d",&search);
  for (c=0;c<n;c++)
  {
    if (array[c] == search)
    {
      printf("%d is present at location %d.\n", search, c+1);
      break;
    }
  }
  if (c == n)
    printf("%d isn't present in the array.\n", search);
getch();
}

OUTPUT


No comments:

Post a Comment