#include
#include
void main()
{
clrscr();
int a[100],i,loc,mid,beg,end,n,flag=0,item;
cout<<"How many element: "; cin>>n;
cout<<"Enter (IN ORDER) the elements of array: "<>a[i];
cout<<"Enter the element to be searched: "; cin>>item;
loc=0;
beg=0;
end=n-1;
while((beg<=end)&&(item!=a[mid]))
{
mid=(beg+end)/2;
if(item==a[mid])
{
cout<<"Search successful :)";
loc=mid;
cout<<"Position of the Item: "<
flag=flag+1;
}
else if(item end=mid-1;
else
beg=mid+1;
}
if(flag==0)
{
cout<<"Search NOT sucessfull :( ";
}
getch();
}
#include
void main()
{
clrscr();
int a[100],i,loc,mid,beg,end,n,flag=0,item;
cout<<"How many element: "; cin>>n;
cout<<"Enter (IN ORDER) the elements of array: "<
cout<<"Enter the element to be searched: "; cin>>item;
loc=0;
beg=0;
end=n-1;
while((beg<=end)&&(item!=a[mid]))
{
mid=(beg+end)/2;
if(item==a[mid])
{
cout<<"Search successful :)";
loc=mid;
cout<<"Position of the Item: "<
}
else if(item end=mid-1;
else
beg=mid+1;
}
if(flag==0)
{
cout<<"Search NOT sucessfull :( ";
}
getch();
}