|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#define M 10;
#include <stdio.h>
void main()
{
static int a[M] = {-12,0,6,16,23,56,80,100,110,115};
int n, low, high, mid, fond;
low = 0;
high = M - 1;
fond = 0;
printf("input a number to be searched: ");
scanf("%d",&n);
while(1)
{
mid = (low + high) / 2;
if(n > a[mid])
{
low = mid;
}
else if(n < a[mid])
{
high = a[mid];
}
else if(n == a[mid])
{
fond = mid;
printf("他在第%d位\n",fond);
break;
}
if (low > high)
{
printf("This is a wrong number");
break;
}
}
}
为啥这么多错误,求高手指点指点
--------------------Configuration: erfenfa - Win32 Debug--------------------
Compiling...
erfenfa.c
F:\C例题\erfenfa\erfenfa.c(6) : error C2143: syntax error : missing ']' before ';'
F:\C例题\erfenfa\erfenfa.c(6) : error C2143: syntax error : missing ';' before ']'
F:\C例题\erfenfa\erfenfa.c(7) : error C2143: syntax error : missing ';' before 'type'
F:\C例题\erfenfa\erfenfa.c(8) : error C2065: 'low' : undeclared identifier
F:\C例题\erfenfa\erfenfa.c(9) : error C2065: 'high' : undeclared identifier
F:\C例题\erfenfa\erfenfa.c(10) : error C2065: 'fond' : undeclared identifier
F:\C例题\erfenfa\erfenfa.c(12) : error C2065: 'n' : undeclared identifier
|
|