C语言题目,不会做,跪求大神帮忙 20
展开全部
//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
#include "time.h"
#include "stdlib.h"
#define N 10
void myfun(int a[],int f){
int i,j,k,t;
printf("%d",*a=rand()%9+1);
for(i=1;i<N;printf("%d",a[i++]=rand()%10));
printf("\n");
for(i=N-1;i>=0;i--){
for(j=i-1;j>=0;j--)
if(f ? a[j]<a[i] : a[j]>a[i]) break;
if(j>=0){
t=a[i];
a[i]=a[j];
a[j]=t;
for(i=j+1;i<N;i++){
for(k=i,j=k+1;j<N;j++)
if(f ? a[k]>a[j] : a[k]<a[j]) k=j;
if(k!=i){
t=a[k];
a[k]=a[i];
a[i]=t;
}
}
break;
}
}
if(i>=0)
for(i=0;i<N;printf("%d",a[i++]));
else
printf("This number is the %s of all.",f ? "maximum" : "minimum");
}
int main(void){
int a[N];
srand((unsigned)time(NULL));
printf("The minimum in maxima:\n");
myfun(a,1);
printf("\n\nThe maximum in minima:\n");
myfun(a,0);
printf("\n");
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询