#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void sort(int a[],int n) {
int i,j,k,t;
for(i = 0; i < n - 1; ++i) {
k = i;
for(j = i + 1; j < n; ++j) {
if(a[k] > a[j]) k = j;
}
if(i != k) {
t =a[i];
a[i] = a[k];
a[k] = t;
}
}
}
int main() {
int i,n = 20;
int a[20];
srand((unsigned)time(NULL));
for(i = 0; i < n; ++i) {
a[i] = rand()%2000 + 1;
if(i && i % 10 == 0) printf("\n");
printf("%5d",a[i]);
}
printf("\n");
sort(a,n);
printf("最大:%d\n",a[n - 1]);
printf("最小:%d\n",a[0]);
printf("中间:%d\n",a[n/2]);
return 0;
}
温馨提示:答案为网友推荐,仅供参考