折半查询中出现的问题。 求指点!
#include<stdio.h>#define N 7
int main()
{
int a[N]={1,2,3,4,5,6,7};
int low,mid,high,x;
low=0;
high=N-1;
printf("please input what you want to search: ");
scanf("%d",&x);
while(low<=high)
{
mid=(low+high)/2;
if(x>a[mid])
{
low=mid+1;
}
else if(x<a[mid])
{
high=mid-1;
}
else if(x=a[mid])
{
printf("%3d",mid);
printf("\n");
break;
}
else
printf("the numble can't be found !");
}
return(-1);
}
这是我编的一个查询数组里面的数的程序,但是在输入不是该数组的数时并没有按我设定的一样输出"the numble can't be found !",要怎样该才能实现?求指点!
[ 本帖最后由 wo叫xiao宝 于 2012-11-21 22:16 编辑 ]