大佬们帮我看看这题,为什么运行时按enter没有任何显示,是不是和指针有关系
#include<stdio.h>#define max 10
int binary_search(int a[], int n,int x)
{
int left = 0;
int right = n - 1;
int mid = (left + right)/2;
while (left <= right)
{
if (a[mid] == x)
{
printf("查找成功!");
return mid;
}
else if (a[mid] < x)
left = mid + 1;
else if(a[mid] > x)
right = mid - 1;
}
return -1;
}
int main()
{
int a[max];
int x,k;
printf("请输入十个数字:\n");
for (int i = 0; i < max; i++)
{
scanf("%d",&a[i]);
}
while (1)
{
printf("请输入你要查找的数字:\n");
scanf("%d", &x);
k = binary_search(a, 10, x);
if (k == -1)
printf("查找失败,没有这个数!");
}
return 0;
}