#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;
}
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;
}
No comments:
Post a Comment