Saturday, October 9, 2010

C Program for Linear Search

Here is my sample of C Program for Linear Search


#include
main()
{
int A[100],i,n,s,ch;
printf("\nEnter the size of the list : ");
scanf("%d",&n);
printf("\nEnter the elements of the list : ");
for(i=0;i
scanf("%d",&A[i]);

while(ch){
printf("\nEnter the element you want to search : ");
scanf("%d",&s);
for(i=0;i
if(s==A[i])
break;
if(i
printf("\nThe element found at index %d",i);
else
printf("\nThe element not found");
printf("\nSearch another element (yes=1,no=0)? ");
scanf("%d",&ch);
}
}

No comments:

Post a Comment