#include <stdio.h>
#define N 11
int zhu(int A[N],int x)
{
int top=0,bottom=11,mid,tag=-1;
while(top<=bottom)
{
mid=(top+bottom)/2;
if(x==A[mid])
{
tag=mid;
return tag;
}else if(x>A[mid]){
bottom=mid-1;
}else if(x<A[mid])
{
top=mid+1;
}
}
return tag;
}
main()
{
int A[N]={90,70,80,10,30,20,50,40,100,60,99};
int i;
int j;
int temp;
int x,tag;
for(i=0;i<=N-1-1;i++)
{
for(j=0;j<=N-1-1-i;j++)
{
if(A[j]<A[j+1])
{
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
}
}
}
printf("排序后:\n");
for(i=0;i<N;i++)
{
printf("%d ",A[i]);
}
printf("\n");
printf("请输入数组中的数:");
scanf("%d",&x);
tag=zhu(A[N],x);
if(tag==-1)
{
printf("%d 没有\n",x);
}else
{
printf("%d 在第 %d 位\n",x,tag+1);
}
}
#define N 11
int zhu(int A[N],int x)
{
int top=0,bottom=11,mid,tag=-1;
while(top<=bottom)
{
mid=(top+bottom)/2;
if(x==A[mid])
{
tag=mid;
return tag;
}else if(x>A[mid]){
bottom=mid-1;
}else if(x<A[mid])
{
top=mid+1;
}
}
return tag;
}
main()
{
int A[N]={90,70,80,10,30,20,50,40,100,60,99};
int i;
int j;
int temp;
int x,tag;
for(i=0;i<=N-1-1;i++)
{
for(j=0;j<=N-1-1-i;j++)
{
if(A[j]<A[j+1])
{
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
}
}
}
printf("排序后:\n");
for(i=0;i<N;i++)
{
printf("%d ",A[i]);
}
printf("\n");
printf("请输入数组中的数:");
scanf("%d",&x);
tag=zhu(A[N],x);
if(tag==-1)
{
printf("%d 没有\n",x);
}else
{
printf("%d 在第 %d 位\n",x,tag+1);
}
}