#include<stdio.h>
#define N 10
search(int c[]); 这个着急用大神 这个程序只能排序,找不到输入的整数啊 在线等 谢谢大哥
int main(void)
{
int a[N],i,j,r,temp;
printf("please input %d numbers\n",N);
for(i=0;i<N;i++)
scanf("%d",&a);
for(i=0;i<N-1;i++)
{
r=i;
for(j=i+1;j<N;j++)
if(a[j]>a[r])
r=j;
if(r!=i)
{
temp=a;
a=a[r];
a[r]=temp;
}
}
printf("the array after sort:\n");
for(i=0;i<N;i++)
printf("%5d",a);
printf("\n");
search();
}
search(int c[])
{
int i,a[10],x,low=0,high=10,mid;
printf("please enter the number to search:\n");
scanf("%d",&x);
while(low<=high)
{
mid=(low+high)/2;
if(x==a[mid])
break;
else if(x>a[mid])
high=mid-1;
else
low=mid+1;
}
if(x==a[mid])
printf("%d is the %dth in array a.\n",x,mid+1);
else
printf("%d is not found!\n",x);