Skip to content

Instantly share code, notes, and snippets.

@78526Nasir
Created February 18, 2016 08:01
Show Gist options
  • Save 78526Nasir/2d38e0cb1feb846d445c to your computer and use it in GitHub Desktop.
Save 78526Nasir/2d38e0cb1feb846d445c to your computer and use it in GitHub Desktop.
Linear Search Implementation in C
/// linear search ///
#include <stdio.h>
main()
{
int a[100],i,n,pos=0,item;
printf("Enter How many elements on your Array: ");
scanf("%d",&n);
printf("\nEnter %d elements values : ",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nEnter a Item to Search: ");
scanf("%d",&item);
for(i=0;i<n;i++)
{
if(a[i]==item)
{
pos=i+1;
break;
}
}
if(pos==0)printf("\nNot Found !\n");
else printf("\nItem Found at Position %d\n",pos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment