把a、b、c这3个变量本身改成a≤b≤c的形式。首先检查a和b的值,如
果a>b,则交换a和b(利用前面讲过的三变量交换法);接下来检查a和xiao,最后检查b和c
(小到大)
#include<stdio.h>
int main() {
int a, b, c, t;
scanf("%d%d%d", &a, &b, &c);
if(a > b) {
t = a;
a = b;
b = t;
}
//执行完毕之后a≤b
if(a > c) {
t = a;
a = c;
c = t;
}
//执行完毕之后a≤c,且a≤b依然成立
if(b > c) {
t = b;
b = c;
c = t;
}
printf("%d %d %d\n", a, b, c);
return 0;
}