Write a c Program to perform Linear Search.
#include<stdio.h>
int main()
{
int array[100],a,c,n;
scanf("%d",&n);
scanf("%d",&a);
for (c=0; c<n; c++)
scanf("%d",&array[c]);
for(c=0; c<n; c++)
{
if (array[c] == a)
{
printf("%d",c);
break;
}
}
if (c == n)
printf("-1");
return 0;
}
No comments:
Post a Comment