Here is a C++ program to search an array elements
SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
int i,a[20],n,serh;
cout<<"How many elements to be stored (max 20) : ";
cin>>n;
cout<<"Enter elements ";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the element to be searched ";
cin>>serh;
for(i=0;i<n;i++)
if(serh==a[i])
{
cout<<"Element is present at "<<i+1<<" position";
return 0;
}
cout<<"Element is not present ";
return 0;
}
using namespace std;
int main()
{
int i,a[20],n,serh;
cout<<"How many elements to be stored (max 20) : ";
cin>>n;
cout<<"Enter elements ";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the element to be searched ";
cin>>serh;
for(i=0;i<n;i++)
if(serh==a[i])
{
cout<<"Element is present at "<<i+1<<" position";
return 0;
}
cout<<"Element is not present ";
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment