1.C语言程序编写——折半查找法
C语言程序编写——折半查找法
#include<stdio.h>
int main()
{ int a[]={ ,折找法折半在线ping测试源码,,,,,9,8,7,6,5,4,3,1,0};
int l=0,r=,mid,x;
scanf("%d",&x);
do
{ mid=(l+r)/2;
if(a[mid]==x)break;
if(x>a[mid])r=mid-1;
else l=mid+1;
}while(l<=r);
if(a[mid]==x)
printf("a[%d]=%d\n",mid,x);
else
printf("无此数\n");
return 0;
}
2024-11-06 13:51
2024-11-06 13:10
2024-11-06 12:54
2024-11-06 12:44
2024-11-06 12:24
2024-11-06 11:53