Wednesday, 19 June 2013

source code: Linear search using C++ [easy and user friendly]


#include <iostream>

using namespace std;

class lin

{
public:
void ls()
{
int ary[100],c,search,number;
cout <<"Enter the number of elements in array you want:"; cin>>number;

cout <<"Input " <<number <<" numbers in the array:" <<endl;

for(c=0; c<number; c++)
{
cin >> ary[c];
}
cout << "Enter the number what to search" <<endl; cin >> search;

for(c=0; c<number; c++)

{
if(ary[c]==search)
{
cout <<search<<" is present at location "<<++c<<endl; break;
}
else if(c==number)
{
cout<<search<<" is not present in array.\n";
}
}

}
};

int main()
{
lin a;
a.ls();
}

No comments:

Post a Comment