已知一有序数列(从小到大排列),要求输入一个数,如果此数在这个数列中则打印在此数列中的序号!否者,打印"no find"。
main()
{
int a,b,c,d,x,s[11];
scanf("%d",&x);
for(a=1;a<=10;a++)
{
s[a]=a;
}
a=d=0;
b=10;
do
{
c=(a+b)/2:
if(x==s[c])
d=1;
else
{
if(xb=c-1;
else
a=c+1;
}
while((a<=b)&&(d==0))
if(d==1)
printf("%d,%d",x,c);
else
printf("no find");
}
你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=951173