1.使用临时变量
#include <stdio.h>
int main()
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a < b)
{
int tmp = 0;
tmp = a;
a = b;
b = tmp;
}
if (a < c)
{
int tmp = 0;
tmp = a;
a = c;
c = tmp;
}
if (b < c)
{
int tmp = 0;
tmp = b;
b = c;
c = tmp;
}
printf("%d %d %d", a, b, c);
return 0;
}
2.未使用临时变量(函数)
#include <stdio.h>
int max(int a, int b)
{
int c = 0;
c = a > b ? a : b;
return c;
}
int min(int a, int b)
{
int c = 0;
c = a < b ? a : b;
return c;
}
int main()
{
int x, y, z, a, b, c, d, e;
scanf("%d %d %d", &x, &y, &z);
a = max(x, y);
b = max(a, z);//三个数中最大值
c = min(x, y);
d = min(c, z);//三个数中最小值
e = x + y + z - b - d ;
printf("%d %d %d\n", b, e, d);
return 0;
}