帮我看一下程序错误

来源:百度知道 编辑:UC知道 时间:2024/05/14 07:13:47
#include<stdio.h>
#define N 10
typedef int datatype;

int BinarySearch( datatype a[N],datatype x,int N)
{
int low=0,mid,high=N-1;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]<x)
low=mid+1;
else
if(a[mid]>x)
high=mid-1;
else return mid;
}
return Notfound;
}
void mian()
{
datatype x,a[N];
int i,j;
for(i=0;i<N;i++)
scanf("%d",&a[i]);
scanf("%d",&x);
j=BinarySearch( const datatype a[],datatype x,int N)
}
VC:
error C2143: syntax error : missing ')' before 'constant'
error C2143: syntax error : missing ';' before 'constant'
fatal error C1004: unexpected end of file found

错的太多了,
已经改好了,和你的比对一下吧:

#include<stdio.h>
#define N 10
typedef int datatype;

int BinarySearch(const datatype a[N],datatype x)
{
int low=0,mid,high=N-1;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]<x)
low=mid+1;
else
if(a[mid]>x)
high=mid-1;
else return mid;
}
return -1;
}
void main()
{
datatype x,a[N];
int i,j;
for(i=0;i<N;i++)
scanf("%d",&a[i]);
scanf("%d",&x);
j=BinarySearch( a,x) ;
}