招跑郑州半挂司机:折半查找

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/10 15:25:03
main()
{
int a[5]={1,3,4,5,6};
int top,bott,mid,n;
clrscr();
scanf("%d",&n);
top=0;
bott=4;
while(top<=bott)
{
mid=(top+bott)/2;
if(a[mid]==n)printf("找到元素\n");
else if(n>a[mid])top=mid+1;
else bott=mid-1;

}
}
程序错在哪里?

if(a[mid]==n)printf("找到元素\n");
改成if(a[mid]==n){printf("找到元素\n");break;}