Monday, 11 September 2017

Linear Search. 



One of the easiest method for searching the element in an array.

Structure:

int Array[10], x; //x is variable for search 
for (int i =0 ; i<10; i++) //Initalize, condition, increment 
{
cin>>Array[i];

cout<<"Enter the element to Search: ";
cin>>x;
for (int i =0 ; i<10; i++) //Initalize, condition, increment 
{
if(Array[i] == x){ cout<<"Number found at position" <<i+1;  break;}
}