请问有大佬可以运行一下这段代码吗?为什么输入a,然后回车,就不断输出了好多东西.
#include <stdio.h>#define M 10
int main()
{
int n,low,high,found,mid,k,a = {1,2,3,4,5,6,7,8,9,10};
low = 0;high = M-1;found = 0;
printf("Please input the search number: ");
#if (0)
do
{
scanf("%d",&n);
getchar();
}while(n < a || n > a);
#endif
while(scanf("%d",&n) != 1)
{
printf("Input Error!");
printf("Please input again!");
getchar;
}
while(low <= high)
{
mid = (low + high)/2;
if(a == n)
{
found = 1;
break;
}
else
{
if(a > n)
{
high = mid-1;
}
else
{
low = mid+1;
}
}
}
if(found == 1)
{
printf("The number is:%d\n",a);
}
else
{
printf("The number is not search!!!");
}
return 0;
} getchar;
getchar(); ba21 发表于 2019-10-28 10:51
getchar;
getchar();
好的好的,谢谢您! ba21 发表于 2019-10-28 10:51
getchar;
getchar();
成功解决问题,谢谢您!
页:
[1]