有那么夸张么……????
两页多纸……!!!多大的纸哈?
我来写个吧,要说也挺简单的呀……
#include <stdio.h>
#define R 15
int main(void)
{
int a[R]={2,5,6,8,11,15,18,20,22,40,60,70,88,90,99};
int low,high,m,i,x;
printf("\nInput the number:__\b\b");
scanf("%d",&x);
low=0;
high=15;
while(low<=high)
{
m=(low+high)/2;
if(x==a[m]) break;
else if (x>a[m]) low=m+1;
else high=m-1;
}
if(low<=high)
printf("%d is found ,the position is %d",x,m); /*这里的m是从0算的要是从1开始算数组中元素就把m改成m+1*/
else
printf("%d is not found \n",x);
getch();
return 0;
}
温馨提示:答案为网友推荐,仅供参考