查找某个数字是否在数组中程序运行问题
#include<stdio.h>#define N 10
main()
{
int a[N];
int mid,low=1,high=N,x,index=-1,found=0;
int b[10],i,j,temp,n=0,m=0;
printf("Please input ten numbers:\n");
for(i=1;i<=10;i++)
scanf("%d",&b[i]);
for(j=1;j<=9;j++)
for(i=1;i<=10-j;i++)
{m++;
if(b[i]>b[i+1])
{
temp=b[i];
b[i]=b[i+1];
b[i+1]=temp;
n++;
}
}
printf("Output ten numbers:\n");
for(i=1;i<=10;i++)
printf("%6d",b[i]);
printf("\nHave %d exchanging\n",n);
printf("Have %d compare\n",m);
printf("Input search date\n");
scanf("%d",&x);
mid=(low+high)/2;
while(low<=high&&found!=1)
{
if(x==a[mid])
{
found=1;
index=mid;
}
else if(x<a[mid])
high=mid-1;
else
low=mid+1;
mid=(low+high)/2;
}
if(found)
printf("%d is on %d \n",x,index);
else
printf("No found");
system("pause");
}
为什么输入的数字(不论是数组里面有没有的数字)都说不载数组内?是数组排列部分的%6d的问题?%6d改成%d\t也找不到数字,为什么?哪错了?