Saturday, May 21, 2011

C program to implement Linear Search

//program for linear search
#include
#include
int main()
{
int a[10],item,n,i;
printf("\n\n\t how many elements do you want to enter in the array:");
scanf("%d",&n);
printf("\n\n\t enter the elements of the array:");
for(int i=0;iscanf("%d",&a[i]);
printf("\n\n\t enter the element to be searched:");
scanf("%d",&item);
for(i=0;i{
if(a[i]==item)
printf("\n\n\t element is found at position %d",i+1);
else
printf("\n\n\t the elememt is not present in the array:");
}
getch();
}

No comments:

Post a Comment