#include <bits/stdc++.h>
using namespace std;
#define N 10
int main()
{
int i,low=0,high=N-1,mid,k=-1,m;
int a[N]={-3,4,7,9,13,45,67,89,100,180};
printf("a数组中的数据如下:\n");
for(i=0;i<N;i++)
printf("%d ",a[i]);
printf("\n");
printf("Enter m: ");
scanf("%d",&m);
while(low<=high){
mid=(low+high)/2;
if(m<a[mid])
high=mid-1;
else if(m>a[mid])
low=mid+1;
else{
k=mid;
break;
}
}
if(k>=0)
printf("m=%d,index=%d\n",m,k);
else
printf("Not be found");
return 0;
}
03-25
794
06-09