#include<iostream.h>
#include<conio.h>
int LinearSearch(int a[],int n,int data);
void main()
{
clrscr();
int a[50],i,n,d,flag;
cout<<"Enter the number of elements ";
cin>>n;
cout<<"Enter the elements";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"Enter the element to be searched";
cin>>d;
flag=LinearSearch(a,n,d);
if(flag==-1)
cout<<"Element Not Found";
else
cout<<"Element found at location"<<flag+1;
getch();
}
int LinearSearch(int a[],int n,int d)
{
int i;
for(i=0;i<n;i++)
{
if(a[i]==d)
return i;
}
return -1;
}
#include<conio.h>
int LinearSearch(int a[],int n,int data);
void main()
{
clrscr();
int a[50],i,n,d,flag;
cout<<"Enter the number of elements ";
cin>>n;
cout<<"Enter the elements";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"Enter the element to be searched";
cin>>d;
flag=LinearSearch(a,n,d);
if(flag==-1)
cout<<"Element Not Found";
else
cout<<"Element found at location"<<flag+1;
getch();
}
int LinearSearch(int a[],int n,int d)
{
int i;
for(i=0;i<n;i++)
{
if(a[i]==d)
return i;
}
return -1;
}