Tuesday, August 27, 2013

C++ Program for iterative linear search

#include<iostream>
using namespace std;
int main(){
int a[40],it,p=0,i,n;
cout<<"Enter the number of elements";
cin>>n;
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<"Enter item to be searched";
cin>>it;
for(i=0;i<n;i++){
if(a[i]==it){
p=i+1;
break;
}
}
if(p>0){
cout<<"item found at "<<p<<" position";
}
else
cout<<"Item not found";

return 0;
}

Output:-


Download the program  :- Pdf and source file(.cpp)

No comments:

Post a Comment

Ads Inside Post