Created
February 18, 2016 08:01
-
-
Save 78526Nasir/2d38e0cb1feb846d445c to your computer and use it in GitHub Desktop.
Linear Search Implementation in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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