简易改进,望大佬指教!
#include <stdio.h>#define M 10
int main()
{
int n,low,high,found,mid,a = {1,2,3,4,5,6,7,8,9,10};
low = 0;high = M-1;found = 0;
printf("Please input the search number: ");
do
{
scanf("%d",&n);
getchar();
}while(n < a || n > a);
while(low <= high)
{
mid = (low + high)/2;
if(a == n)
{
found = 1;
break;
}
else
{
if(a > n)
{
high = mid-1;
}
else
{
low = mid+1;
}
}
}
if(found == 1)
{
printf("The number is:%d\n",a);
}
else
{
printf("The number is not search!!!");
}
return 0;
} 楼主,这个代码是干什么的,原来是什么样子,你改进了什么,是不是起码应该有个交代? jackz007 发表于 2019-10-28 11:05
楼主,这个代码是干什么的,原来是什么样子,你改进了什么,是不是起码应该有个交代?
二分法,寻找我输入的值是否在开始定义的数组中。改进是能不能判断输入的非法字符。求指教
页:
[1]