c语言折半法求位置
#include<stdio.h>int main()
{
int a[10]={5,2,3,0,96,56,45,25,6,20};
int i,x,leap,low,high,mid;
i=0;leap=-1;
scanf("%d",&x);
while(leap=-1&&i<=9)
{
leap=0;
i++;
}
if(leap==1)
printf("无");
if(leap==-1)
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]==x) break;
else
if(a[mid]>x) high=mid-1;
else low=mid+1;
}
printf("%d",x);
}
用折半法查找位置。我都写蒙了 谁帮我看看啊!