被你带沟里去了,输入数组是b处理的数组是a.哎,惭愧
#include
#define N 10
void main(void)
{
int a[N];
int mid;
int low=0;
int high=9;
int x;
int index;
int found=0;
int b[10];
int i;
int j;
int temp;
int n;
int m=0;
printf("Please input ten numbers:\n");
for(i=0;i<10;i++)
{
scanf("%d",&b[i]);
}
for(j=0;j<10;j++)
{
for(i=0;i<10-j;i++)
{
{
m++;
if(b[i]
{
temp=b[i];
b[i]=b[i+1];
b[i+1]=temp;
n++;
}
}
}
}
printf("Output ten numbers:\n");
for(i=0;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);
printf("input x=%d\n",x);
mid=(low+high)/2;
while((low<=high)&&(found!=1))
{
if(x==b[mid])
{
found=1;
index=mid;
}
else if(x>b[mid])
{
high=mid-1;
mid=(low+high)/2;
}
else
{
low=mid+1;
mid=(low+high)/2;
}
}
if(found)
printf("%d is on %d \n",x,index);
else
printf("No found");
//system("pause");
//return 0;
}
* 坚持与积累成就C语言王者之路 *