本帖最后由 苏子瞻201068 于 2015-9-19 10:00 编辑
#include<stdio.h>
int main() {
int t[15]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int a,b,c,mid; a=0;b=14;
scanf("%d",&c);
while(a<=b)
{
mid=(a+b)/2;
if(c==t[mid])
{ printf("%d",t[mid]); break; } else if(c>t[mid])
{a=mid+1; else b=mid-1; }
if(a>b)
printf("无此元素");
return 0;
}
}
|