#include<stdio.h>
int main()
{
int a[10]={7,9,12,18,21,25,33,39,45,60};
int x,left=0,right=9,mid,flag=0;
printf("Input a number to be searched:\n");
scanf("%d", &x);
if(x>=a[left]&&x<=a[right])
while(!flag&&right>=left)
{
mid=(left+right)/2;
if(a[mid]==x)
flag==1;
else if(x>a[mid])
left=mid+1;
else
right=mid-1;
}
if(flag==1)
printf("position is %d", mid);
else
printf("Not Exist!");
return 0;
}
onemoo
飞奔的王麻子
相关分类