#include<stdio.h> #define N 10 int main() { int i,a[N]={-3,4,7,9,13,45,67,89,100,180},low=0,high=N-1,mid,k=-1,m; 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!\n"); }
标签:折半,int,1.9,mid,查找,low,printf From: https://www.cnblogs.com/xuan-2004/p/17353620.html