conditions for a linear search :
1.the elements must be a sorted order.
-----------------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
main()
{
int a[10] = {1,2,3,4,5,6,7,8,9,10};
int n,i;
printf("enter the number which u want to search\n");
scanf("%d",&n);
for(i=0;i<=9;i++)
{
if(a[i] == n)
{
printf("the number is find i.e %d\n",a[i]);
}
}
}
----------------------------------------------------------------------------------------------------------------------------------
op :
enter the number which u want to search
5
the number is find i.e 5
0 comments: