#include<iostream.h>
#include<conio.h>
void main()
{
int a[15],n,i,loc,item,chk=0;
clrscr();
cout<<endl<<"enter the no of elements :";
cin>>n;
cout<<endl<<"enter the elements :";
for(i=0;i<n;i++)
{
cout<<endl<<"a["<<i<<"] = ";
cin>>a[i];
}
cout<<endl<<"enter the item to be searched :";
cin>>item;
for(i=0;i<n;i++)
{
if(a[i]==item)
{
loc=i;
chk=1;
}
}
if(chk==1)
{
cout<<endl<<"item is present at "<<loc+1<<" loc";
}
else
{
cout<<endl<<"item is not present in the list :";
}
getch();
}
No comments:
Post a Comment