Linear search in array C programming

Logic for linear search is easy : you can see the c program in following steps:

//linear search:
#include<stdio.h>
#include<conio.h>
int main()
{

int a[100],item,i,c=0;
for(i=0;i<4;i++)
{
printf("enter %d value:",i+1);
scanf("%d",&a[i]);

}
printf("enter to search:");
scanf("%d",&item);


for(i=0;i<4;i++)
{
if(item==a[i])
{
printf("%d found on %d\n",item,i+1);
c=c+1;
}

}
printf("count= %d",c);//counting the repeat
getch();
}

...............................
Result:

Other C Programming:


No comments

Powered by Blogger.