Linear search program in c++
#include <iostream>
using namespace std;
int main()
{
int a[10],i,num,index;
cout<<"\n"<<"enter 10 numbers";
for(i=0;i<10;i++)
cin>>a[i];
cout<<"enter the number to be searched\n";
cin>>num;
for(i=0;i<10;i++)
{
if(a[i]==num)
{index=i;
break;
}
}
cout<<"\nelement found at index no"<<index;
return 0;
}
Comments
Post a Comment