Implement Sequential search algorithms Using C
#include<stdio.h>
#include<conio.h>
Void linear_search(int a[],int,int);
void main()
{ clrscr();
int a[20],n,i,key;
printf("nhow many number enter in list:");
scanf("%d",&n);
printf("nArrary is=n");
for(i=0;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("n enter element to be search in the list");
scanf("%d",&key);
linear_search(a,n,key);
getch();
}
voidlinear_search(int a[],intn,int key)
{
int flag=0;
int i;
for(i=0;i<n;i++)
{
if(a[i]==key)
{
flag=1;
break;
}
}
if(flag==1)
{
printf("search is successful at location: %d",i);
}
else
{
printf("search is unsuccessful");
}
}
0 Comments