PROGRAM TO SEARCH A NUMBER IN AN ARRAY:
#include<iostream>
#include<cmath>
using namespace std;
main()
{int a[100],b,c,d,s,e,m;
cout<<"ENTER THE NO OF ELEMENTS";
cin>>b;
cout<<"ENTER THE ELEMENTS";
for(c=0;c<b;c++)
cin>>a[c];
cout<<"ENTER THE VALUE TO SEARCH";
cin>>d;
s=0;
e=b;
m=(s+e)/2;
while(b<=e && a[m]!=d)
{
if(a[m]>d)
{e=m-1;}
else if(a[m]<d)
s=m+1;
}
m=m+1;
cout<<"VALUE "<<d<<" EXIST AT "<<m;
}
#include<iostream>
#include<cmath>
using namespace std;
main()
{int a[100],b,c,d,s,e,m;
cout<<"ENTER THE NO OF ELEMENTS";
cin>>b;
cout<<"ENTER THE ELEMENTS";
for(c=0;c<b;c++)
cin>>a[c];
cout<<"ENTER THE VALUE TO SEARCH";
cin>>d;
s=0;
e=b;
m=(s+e)/2;
while(b<=e && a[m]!=d)
{
if(a[m]>d)
{e=m-1;}
else if(a[m]<d)
s=m+1;
}
m=m+1;
cout<<"VALUE "<<d<<" EXIST AT "<<m;
}