#include<iostream>
using namespace std;
int checksort(int a[20],int n)
{
int c;
for(int i=0;i<n-1;i++)
{
if(a[i]<a[i+1])
c=1;
else
{
c=0;
break;
}
}
return c;
}
void search(int a[20],int h,int key)
{
int l=0;
int mid,c=0;
while(h>=l)
{
mid=(l+h)/2;
if(a[mid]==key)
{
c=1;
break;
}
else
{
if(a[mid]<key)
l=mid+1;
else if(a[mid]>key)
h=mid;
}
}
if(c==1)
cout<<"found:"<<endl;
else
cout<<"not found"<<endl;
}
int main()
{
cout<<"how many elements:";
int n;
cin>>n;
cout<<"enter the elements in sorted order:";
int a[20];
for(int i=0;i<n;i++)
cin>>a[i];
int j=checksort(a,n);
if(j)
{
cout<<"enter the no to search:";
int p;
cin>>p;
search(a,n-1,p);
}
else
cout<<"the elements are not in sorted order"<<endl;
return 0;
}
using namespace std;
int checksort(int a[20],int n)
{
int c;
for(int i=0;i<n-1;i++)
{
if(a[i]<a[i+1])
c=1;
else
{
c=0;
break;
}
}
return c;
}
void search(int a[20],int h,int key)
{
int l=0;
int mid,c=0;
while(h>=l)
{
mid=(l+h)/2;
if(a[mid]==key)
{
c=1;
break;
}
else
{
if(a[mid]<key)
l=mid+1;
else if(a[mid]>key)
h=mid;
}
}
if(c==1)
cout<<"found:"<<endl;
else
cout<<"not found"<<endl;
}
int main()
{
cout<<"how many elements:";
int n;
cin>>n;
cout<<"enter the elements in sorted order:";
int a[20];
for(int i=0;i<n;i++)
cin>>a[i];
int j=checksort(a,n);
if(j)
{
cout<<"enter the no to search:";
int p;
cin>>p;
search(a,n-1,p);
}
else
cout<<"the elements are not in sorted order"<<endl;
return 0;
}