为什么查不出数来啊?
#include <iostream>using namespace std;
#define N 10
void print_maopao(int a[])
{
int i;
cout<<"排序的结果是:"<<endl;
for(i=0;i<N;i++)
cout<<a[i]<<endl;
}
void maopao(int a[])
{
int i,j,k;
for(i=0;i<=N-1;i++)
for(j=0;j<=N-i-1;j++)
if(a[j]>a[j+1])
{
k=a[j];
a[j]=a[j+1];
a[j+1]=k;
}
}
int chazhao(int a[],int num)
{
int start=0,end=N-1,mid;
int flag=0;
mid=(start+end)/2;
do{
if(num>a[mid])start=mid+1;
else if(num<a[mid])end=mid-1;
else
{
flag=1;
break;
}
}while(start<=end);
if(flag==1)
{
cout<<"找到这个数在mid+1上"<<mid+1<<endl;
return(mid+1);
}
else
{
cout<<"找不到该数!"<<endl;
return(0);
}
}
void main()
{
int a[N],num;
int i;
cout<<"请输入十个数:"<<endl;
for(i=0;i<N;i++)
cin>>a[i];
maopao(a);
print_maopao(a);
cout<<"请输入你要查找的数:"<<endl;
cin>>num;
chazhao(a,num);
}