else if 显示错误
#define M 10#include<stdio.h>
void main()
{
static int a={-12,0,6,16,23,56,80,100,110115};//static将数组保存在数据区DATA,没有则保存在堆栈区
int n, low, mid, high, found; //一个程序在编译运行时,普通变量是存放在栈区
low = 0;
high = M-1;
found = 0;
printf("Please input a number:\n");
#if (0)//注释
do
{
scanf("%d",&n);
getchar();
}while(n < a||n > a);
#endif
while(("%d",&n)!= 1)
{
printf("Illegal input!!\nPlease input again");
}
/*if(n<a||n>a);
{
printf("There is no %d......\n",n);
}*/
while (low <= high)
{
mid = (low + high)/2;
{
found = 1;
break;
}
else if(n > a)
{
low = mid + 1;
}
else
{
high = mid -1;
}
}
if (1 == found)
{
printf("The index of %d is %d\n",n,mid);
}
else
{
printf("There is no %d.....\n",n);
}
}
错误提醒:error else without a previous if 检测不到if
#define M 10
#include<stdio.h>
int main()
{
static int a={-12,0,6,16,23,56,80,100,110115};//static将数组保存在数据区DATA,没有则保存在堆栈区
int n, low, mid, high, found; //一个程序在编译运行时,普通变量是存放在栈区
low = 0;
high = M-1;
found = 0;
printf("Please input a number:\n");
#if (0)//注释
do
{
scanf("%d",&n);
getchar();
}while(n < a||n > a);
#endif
while(("%d",&n)!= 1)
{
printf("Illegal input!!\nPlease input again");
}
/*if(n<a||n>a);
{
printf("There is no %d......\n",n);
}*/
while (low <= high)
{
mid = (low + high)/2;
if(xxx)
{
found = 1;
break;
}
else if(n > a)
{
low = mid + 1;
}
else
{
high = mid -1;
}
}
if (1 == found)
{
printf("The index of %d is %d\n",n,mid);
}
else
{
printf("There is no %d.....\n",n);
}
return 0;
}
无符号整形 发表于 2018-8-9 20:54
检测不到if
谢谢~确实是这个问题,我讲怎么找不到呢,原来是被自己删掉了{:5_109:}
页:
[1]