#include<iostream>
using namespace std;
int main()
{
int linearsearch();
int binarysearch();
cout<<"\nThe total numbers in your linear search are "<<linearsearch();
cout<<"\nThe number u searched via Binary search is " <<binarysearch();
system ("pause");}
int linearsearch()
{int sc[100],n,count=0,y;
cout<<"How many numbers u want to enter?";
cin>>y;
cout<<"Enter the numbers\n";
for(int i=0; i<y; i++)
{cin>>sc[i];}
cout<<"Enter a number for the query! via linear search ";
cin>>n;
for(int j=0; j<y;j++)
{if(sc[j]==n)
{
count=count+1;
}}
if(count==1)
{
cout<<"The requred query "<<n<<" is found! \n";
}
else
{
cout<<"The required query cannot be found! \n";}
return y; }
int binarysearch()
{int a[10],n,beg,end,mid,x;
cout<<"\nNo of element in array\t";
cin>>n;
cout<<"enter the element\n";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\nEnter item to be searched via Binary search\t";
cin>>x;
beg=0;end=n;
mid=(beg+end)/2;
while(beg<=end&&a[mid]!=x)
{
if(x<a[mid])
{
end=mid-1;
}
else
{
beg=mid+1;
}
mid=(beg+end)/2;
}
if(a[mid]==x)
{
cout<<"\nItem found at location\n "<<mid+1;
}
else
{
cout<<"\nItem not found\n";
}
return x;}