一个低级的错误!大家来看看
#include<stdio.h> int binsearch(int x,int v[],int n);
int main() { int a,k,i,c,b[10]; c=10; printf("查找的数:"); scanf("%d",a); printf("从小到大输入:"); for(i=0;i<=9;i++) scanf("%d",&b[i]); binsearch(a,b[],c); return k; printf("这是第%d个数\n",k); } /*binsearch:find x in v[0]<=v[1]<=...<=v[n-1]*/ int binsearch(int x,int v[],int n) { int low,high,mid;
low=0; high=n-1; mid=(low+high)/2; while (low<=high&&x!=v[mid]){ if(x<v[mid]) high=mid-1; else low=mid+1; mid=(low+high)/2; } if(x==v[mid]) return mid;/*found match*/ else return -1;/*no match*/ }