关于二分查找法
#include<stdio.h>void main()
{
int c[15];
int i,n,low,high,mid,k=0;
printf("Please enter 15 numbers(from big to small):\n");
for(i=0;i<15;i++)
{
scanf("%d",&c[i]);
}
printf("Please enter a number:");
scanf("%d",n);
low=0;
high=14;
while(1)
{
mid=(low+high)/2;
if(n==c[mid])
{
printf("di %d ge yuan su shi %d.\n",mid,n);
break;
}
else if(n<c[mid])
{
low=mid+1;
}
else if(n>c[mid])
{
high=mid-1;
}
k++;
if(k>4)
{
printf("No this number in it.\n");
break;
}
}
}
求高手指点错在哪里了,输入完n之后就出现红叉叉报错了,为嘛捏???