算法设计
[绪论-1.16] 试写一算法,自大到小依次输出顺序读入的三个整数X,Y和Z的值。
#include<iostream>
using namespace std;
void Sort(int& x, int& y, int& z) {
int temp = 0;
if (x < y) {
temp = x;
x = y;
y = temp;
}
if (z > x) {
temp = x;
x = z;
z = y;
y = temp;
}
else if (z > y) {
temp = y;
y = z;
z = temp;
}
}
int main() {
int i, j, k;
cin >> i >> j >> k;
Sort(i, j, k);
cout << i << ' ' << j << ' ' << k << endl;
cin >> j;
return 0;
}