Sunday, February 4, 2018

Linear Search

Linear Search in C.Linear search basically works on find out a matching number index from an array.
Linear Search known as Sequential Search.

#include <stdio.h>
#define MAX 50

int main()
{
int arr[MAX];
int i,j,size;
scanf("%d" ,&size);
for(i=0;i<size;i++)
{
scanf("%d", &arr[i]);
}
     printf("Enter the number to search\n");
    scanf("%d",&j);
   
    for(i=0; i<size; i++)
    {
      if(arr[i] == j)
      {
      printf("number %d  location %d .\n", j, i);
      }                 
    }       
    return 0;
}

No comments:

Post a Comment