//Program to linearly search an element in array using C++.
#include<iostream.h>
#include<conio.h>
void main()
{
int i, k, loc, item, data[50], n;
clrscr();
cout<<"Enter the number of elements in the array:";
cin>>n;
cout<<"Enter the value of "<<n<<" elements:";
for(i=0; i<n; i++)
{
cin>>data[i];
}
loc=-1;
cout<<endl<<"Enter the given element";
cin>>item;
for(k=0; k<n; k++)
{
if(data[k]==item)
{
loc=k;
}
}
if(loc==-1)
{
cout<<endl<<"Given element is not present";
}
else
{
cout<<endl<<"Given element is present at location="<<loc;
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int i, k, loc, item, data[50], n;
clrscr();
cout<<"Enter the number of elements in the array:";
cin>>n;
cout<<"Enter the value of "<<n<<" elements:";
for(i=0; i<n; i++)
{
cin>>data[i];
}
loc=-1;
cout<<endl<<"Enter the given element";
cin>>item;
for(k=0; k<n; k++)
{
if(data[k]==item)
{
loc=k;
}
}
if(loc==-1)
{
cout<<endl<<"Given element is not present";
}
else
{
cout<<endl<<"Given element is present at location="<<loc;
}
getch();
}