Write a C program to implement Linear search.


#include<stdio.h>
main()
{
int n,i,a[30],s,j,f=0;
printf("\n\n\t\tLINEAR SEARCH\n");
printf("\t\t**************\n");
printf("\nEnter the Number of Terms :\n\n");
scanf("%d",&n);
printf("\n Enter the Number of Elements:\n\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n Enter The Elements To Be Searched:\n\n");
scanf("%d",&s);
for(i=0;i<n;i++)
{
if(a[i]==s)
{
f=1;
printf("\n The Elements in The Position %d",i+1);
break;
}
}
if(f==0)
{
printf("\n\n The Element is Not Found\n");
}
getch();
}

0 comments:

Feel free to contact the admin for any suggestions and help.