各位大虾帮忙找错!
#include<stdio.h>main()
{ int i,j,t,k,low,high,mid,a[10];
printf("Please enter ten numbers:");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(j=0;j<9;j++)
for(i=0;i<9-j;i++)
if(a[i]<a[i+1])
{ t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
for(i=0;i<10;i++)
printf("%3d",a[i]);
printf("\n");
printf("Please enter one number to be search:\n");
scanf("%d",&k);
low=0;
high=9;
mid=(low+high)/2;
while(low<high&&k!=a[mid])
{ if(k<a[mid])
high=mid-1;
else
low=mid+1;
mid=(low+high)/2 ;
}
if(k==a[mid])
printf("%d is at position %d.of array.",k,mid);
else
printf("%d is not in array.",k);
getch();
}
为什么老是输出ELSE的结果?!
还有麻烦下帮忙在若不存在的情况下插入该数到适当位置,请大家帮帮忙!