LINEAR SEARCH for an array in c++




Linear search for an array



Linear search is used to search out the required number from a very large array of elements




#include <iostream>
using namespace std;
void main ()
{
          const int size=5;
          int a[size]={4,5,6,7,7};
         
         
          int n;
          cout<<"enter the no which you want to search:";
          cin>>n;
          bool found=false;
          for(int i=0;i<size&&!found;i++)
                   if(a[i]==n)
                             found=true;
                   if(found ==true)
                             cout<<"Number:"<<n<< "is found at location:"<<i<<endl;
                   else
                             cout<<"Number is NOT found";
}