#include<stdio.h>int main() {int num[3];printf("请输入3组数字:");for (int i = 0; i < 3; i++)scanf("%d", &num[i]);for (int i = 0; i < 2; i++) { //每次选出最小值放在数组前面for (int j = i + 1; j < 3; j++) {if (num[j] < num[i]) {int tmp = num[j]; //通过中间变量,将min和max交换位置num[j] = num[i];num[i] = tmp;}}}for (int i = 0; i < 3; i++)printf("%d ", num[i]);
}
运行结果:
本章C语言经典例题合集:http://t.csdnimg.cn/FK0Qg