Friday, 15 November 2013

C program for linear search


#include<stdio.h>
int main()
{
int a[10],i,n,m,c=0;
printf("enter the size of an array : ");
scanf("%d",&n);
printf("enter the elements of an array: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("enter the number to be search: ");
for(i=0;i<n-1;i++)
{
if(a[i]==m)
{
c=1;
break;
}
}
if(c==0)
{
printf("the no. is not in the list");
else
printf("the no. is found");
}
return 0;
}

No comments:

Post a Comment