WAP for linear search using while
#include<conio.h>
#include<iostream.h>
void main()
{
int item,a[20],n,i,loc;
cout<<"\n enter size of array :";
cin>>n;
cout<<"\n enter element of array :";
for(i=1;i<=n;i++)
cin>>a[i];
cout<<"\n enter element which is to be search :";
cin>>item;
a[n+1]=item;
loc=0;
while(a[loc]!=item)
{
loc++;
}
if(loc==n+1)
{
loc=0;
cout<<"\n ITEM is not found :";
}
else
cout<<"\n ITEM is found at location :"<<loc;
getch();
clrscr();
}
/* OUTPUT
enter size of array :6
enter element of array :12 45 23 52 48 45
enter element which is to be search :23
ITEM is found at location :3
No comments:
Post a Comment