Linear Search In array code

// Linear Search

#include<stdio.h>
main()
{
 int a[5],i,x,pos;
 printf("Enter array\n");
 for(i=0;i<5;i++)
 scanf("%d",&a[i]);
 printf("Enter element to search\n");
 scanf("%d",&x);
 for(i=0;i<5;i++)
 {
  if(x==a[i])
  {
   pos=i;
   break;
  }
 }
 if(i==5)
 printf("Element not Found\n");
 else
 {
  printf("Element found At postion = %d",pos);
 }
}

No comments:

Post a Comment