折半查找错在哪?
#include<stdio.h>#define N 10
int fun(int a[],int m)
{
int low=0,high=N-1,mid;
{
while(low<=high)
mid=(low+high)/2;
if(m<a[mid])
high=mid-1;
else if(m>a[mid])
low=mid+1;
else
return (mid);
}
return (-1);
}
main()
{
int i,a[N]={1,2,3,4,5,6,7,8,9,10},k,m;
printf("\nPlease enter arrye:\n");
for(i=0;i<N;i++)
scanf("%d",&a[i]);
printf("enter m\n");
scanf("%d",&m);
k=fun(a,m);
if(k>=0)
printf("m=%d,index=%d\n",m,k);
else
printf("not be fount");
}