#include
#include
#define N 10
//非递归法在N个数中找出小于0的最大数
void fin(int a[],int n){
int i,min0max=0;
for(i=0;i if(a[i] min0max=a[i];
break;
}
for(i=0;i if(a[i]min0max)min0max=a[i];
}
printf("非递归法 the number required is %d\n",min0max);
}
//递归法在N个数中找个小于0的最大数
int f(int a[],int little,int high){
int max1,max2,mid,min0max;
if(little==high){
if(a[little] else return 0;
}
if(little+1==high){
if((a[little]*a[high])>0){
if(a[little]>0&&a[high]>0)return 0;
else if(a[little] else min0max=a[little];
}
if((a[little]*a[high]) if(a[little] else min0max=a[high];
}
return min0max;
}
else {
mid=(little+high)/2;
max1=f(a,little,mid);
max2=f(a,mid+1,high);
if(max1*max2==0){
if(max1 else return max2;
}
else if(max1 else return max1;
}
}
void main(){
int a[N]={2,1,3,5,-4,6,-2,8,-6,-3};
int min0max;
min0max=f(a,0,N-1);
printf("递归法 the number required is %d\n",min0max);
fin(a,N);
system("pause");
}