LINEAR SEARCH C++
This search technique compares the each value of the array to the value to be searched. as the value matches the array value it execute the break statement......./.
//use header files syntax according to the compiler
#include <iostream.h>
#include<conio.h>
void main()
{
int m,i,flag=0;
int arr[8];
cout<<"Enter Eight elements in the array";
for(i=0;i<8;i++)
cin>>arr[i];
cout<<"Enter the element to be searched ";
cin>>m;
i=0;
while(i<8)
{
if (m==arr[i])
{
flag=1;
break;
}
i++;
}
if (flag!=1)
cout<<"number is not present in the list";
else
cout<<"number is present at "<<" i+1 <<"position";
cin>>m;
i=0;
while(i<8)
{
if (m==arr[i])
{
flag=1;
break;
}
i++;
}
if (flag!=1)
cout<<"number is not present in the list";
else
cout<<"number is present at "<<" i+1 <<"position";
getch();
}
}