c语言二分法
#include <stdio.h>#define M 10
void main()
{
static int a={-12,0,6,16,23,56,80,100,110,115};
int n,low,mid,high,found;
low=0;
high=M-1;
found=0;
printf("Please input a number:\n");
scanf("%/d",&n);
while(low<=high)
{
mid=(low+high)/2;
if(n==a)
{
found=1;
break;
} /*找到,结束循环*/
else if(n>a)
{
low=mid+1;
}
else
{
high=mid-1;
}
}
if(found==1)
{
printf("The index of %d is %d\n",n,mid);
}
else
{
printf("There is not %d......\n",n);
}
}
不知道究竟哪里出了问题,希望大神帮我指证一下 scanf("%/d",&n);
scanf("%d",&n); "%/d" 中间的斜杠/是认真的吗?
页:
[1]