c语言问题,青椒大虾

来源:百度知道 编辑:UC知道 时间:2024/05/15 10:43:05
#include <stdio.h>
void main()
{
int x,t,m=0,n=11,a[11];
scanf("%d",&x);

int a[11]={05,13,19,21,37,56,64,75,80,88,92};
for(t=0;x=a[t];)
{
t=(int)(m+n)/2;
if(x>a[t] && x<a[n])
m=t;
else
n=t;
if(x=a[t])
printf("x is the %d number",t);
break;
if(t=n)
printf("x is not in the number group");
}
}

--------------------Configuration: L6_1 - Win32 Debug--------------------
Compiling...
L6_3.c
C:\Users\TOmmy\教材\C语言\L6折半查找\L6_3.c(7) : error C2143: syntax error : missing ';' before 'type'
执行 cl.exe 时出错.

L6_3.obj - 1 error(s), 0 warning(s)

修改如下:

//---------------------------------------------------------------------------

#include <stdio.h>
void main()
{
int x,t,m=0,n=11,a[11]={05,13,19,21,37,56,64,75,80,88,92};
scanf("%d",&x);

for(t=0;x=a[t];)
{
t=(int)(m+n)/2;
if(x>a[t] && x<a[n])
m=t;
else
n=t;
if(x==a[t])
printf("x is the %d number",t);
break;
if(t==n)
printf("x is not in the number group");
}
}

//---------------------------------------------------------------------------

你是不是想实现:已知一个数组,从键盘输入另一个数,判断是否在该数组内啊。其实这个程序可以很简单就实现了,不需要你写的那么繁琐,程序比较重要的是可读性和占内存的大小,所以你可以考虑用我给你写的程序,下面是运行结果的截图

#include <stdio.h>

void main()

{

 int x,t,flag=0,a[11]={05,13,19,21,37,56,64,75,80,88,92};

 scanf("%d",&x);

 for(t=0;t<11;t++)