小菜的一个关于二分法得问题。。。急
#include<stdio.h>int search(int array[],int i);
int main()
{
int i,j,result;
int array[10]={1,2,3,4,5,6,7,8,9,10};
printf("please enter the number you want to search");
while(1){
scanf("%d",&i);
if(i<1||i>10){
printf("please enter the number from 1 to 10");
}else{
break;
}
result=search(array,i);
printf("the result is %d",result);
return 0;
}
int search(int array[],int i)
{
int mid,low,upper;
low=0;
upper=10;
mid=(low+upper)/2;
while(low<upper){
if(array[mid]==i)
return mid;
else if(array[mid]>i)
upper=mid-1;
else
low=mid+1;
mid=(low+upper)/2;
}
}
调试时总是显示 mid low upper 未声明,是什么原因啊??