#include <stdio.h>
#define N 10
void main()
{
int n,top,bot,mid,i;
int a[N];
for(i=0;i<N;i++) scanf("%d",&a[i]); //输入N个数
printf("\nPlease enter the number you are looking for:");
scanf("%d",&n); //输入要寻找的数
top = 0;
bot = N;
while(top<=bot){
mid = (top+bot)/2;
if(n<a[mid]) bot = mid-1;
else if(n>a[mid]) top = mid+1;
else break;
}
if(top>bot) printf("%d Don't find!!!'",n);
else printf("%d在第%d个",n,mid+1);
}
C语言-二分法
最新推荐文章于 2022-04-27 21:13:21 发布