Program- Liner
Search
// Liner search
#include<stdio.h>
#include<conio.h>
void
linear_search(int l[],int,int);
void main()
{
int
i,j,n,no,l[50];
clrscr();
printf("\n
How Many Elements You Want To Enter :
");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf
("\n Enter a[%d] : ",i);
scanf("%d",&l[i]);
}
printf("\n
Enter The Value To Be Searched : ");
scanf("%d",&no);
linear_search(l,n,no);
getch();
}
void linear_search(int
l[],int n, int e)
{
int
i,flag=0;
for(i=0;i<n;i++)
{
if(l[i]==e)
{
printf("\n
Search is Successful");
printf("\n
Elements %d Found At Location : %d", e,i+1);
flag=1;
}
}
if(flag==0)
{
printf("\n\nSearch
Is Unsuccessful");
}
getch();
}
Posted By :Ruchita Pandya
No comments:
Post a Comment