折半找数字
这是书上的程序,我怎么找不到,运行了,出现的问题是找不到#include "stdio.h"
#define n 15
void main()
{
int i,number,top,bott,mid,loca, a[n],flag=1,sign;
char c;
printf("shu ru shu zhi:\n");
scanf("%d",&a[0]);
i=1;
while (i<n)
{
scanf("%d",&a[i]);
if (a[i]>=a[i-1])
i++;
else printf("chong xin shu ru:\n");
}
printf("\n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("\n");
while (flag)
{printf("yao zhao de shu zhi:" );
scanf("%d",&number);
sign=0;
top=0;
bott=n-1;
if((number<a[0])||(number>a[n-1]))
loca=-1;
while ((!sign)&&(top>=bott))
{ mid=(bott+top)/2;
if(number==a[mid])
{ loca=mid;
printf("zhao dao le:%d shi zai di %d ge shu zhi.",number,loca+1);
sign=1;
}
else if(number<a[mid])
bott=mid-1;
else top=mid+1;
}
if((!sign)||(loca==-1))
printf("mei you zhao dao %d \n",number);
printf("shi fou ji xu zhao?y/n?");
scanf(" %c",&c);
if((c=='n')||(c=='N'))
flag=0;
}
}
运行结果就是找不到,请高手帮忙,谢谢了