二分法查找程序,帮忙找找错
#include <stdio.h>int binary_search(int [],int,int);
int main()
{
#define kongjian 81
int nums [kongjian];
int n=0;
int key;
printf("输入数据:\n");
while(scanf("%d",&nums[n])==1)
{n++;}
printf("输入要查找的数:\n");
scanf("d%",&key);
if(binary_search>0)
printf("位置是第%d个\n",binary_search);
if(binary_search==-1)
printf("没有找到\n");
return 0;
}
int binary_search(int nums[],int key,int n )
{ int mid,front=0,back=n-1;
while (front<=back)
{mid=(front+back)/2;
if(nums[mid]==key)
return mid;
if (nums[mid]<key)
front = mid+1;
else back = mid-1;
}
return -1;
}