//program to implement binary search
#include
#include
void main()
{
clrscr();
int a[10],min=0,max=9,mid=0,p=-1,num;
for(int i=0;i<=9;i++)
{ cin>>a[i]; }
cout<<"enter: ";
cin>>num;
while((max>=mid)&&(p==-1))
{ mid=(min+max)/2;
if(a[mid]==num)
{ p=mid; }
else if(a[mid]>num)
{ min=mid+1; }
else
{ max=mid-1; }
}
if(p>-1)
{ cout<<"at"<
else
{ cout<<"sorry!"; }
getch();
}
2007-02-25
01:31:18
·
4 answers
·
asked by
jayati j
2
in
Computers & Internet
➔ Software
i didn't find any answers good...infact i found my mistake and that was with lines...min=mid+1;...and another...max=mid-1;
2007-02-25
19:09:54 ·
update #1