📄 program_6_7.cpp
字号:
// program 6.7: Input three numbers and output them
// in sorted order
#include <iostream>
using namespace std;
// swap two values
void Swap(int &x, int &y) {
int tmp = x;
x = y;
y = tmp;
return;
}
// sort three numbers into nondecreasing order
void Sort3(int &a, int &b, int &c) {
if (a > b)
Swap(a, b);
if (a > c)
Swap(a, c);
if (b > c)
Swap(b, c);
return;
}
// read three numbers and output them in sorted order
int main() {
cout << "Please enter three integers: ";
int Input1;
int Input2;
int Input3;
cin >> Input1 >> Input2 >> Input3;
int Output1 = Input1;
int Output2 = Input2;
int Output3 = Input3;
// Sort the three numbers
Sort3(Output1, Output2, Output3);
// Output the sorted numbers
cout << Input1 << " " << Input2 << " " << Input3
<< " in sorted order is "
<< Output1 << " " << Output2 << " " << Output3 << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -