B、输入三个实数,按递增顺序输出。 注意用if语句写程序。用c++做
时间: 2024-02-20 16:02:10 浏览: 64
可以使用以下C++代码实现该功能:
```cpp
#include <iostream>
using namespace std;
int main() {
double a, b, c;
cout << "请输入三个实数,用空格隔开:" << endl;
cin >> a >> b >> c;
if (a <= b && a <= c) {
cout << a << " ";
if (b <= c) cout << b << " " << c << endl;
else cout << c << " " << b << endl;
}
else if (b <= a && b <= c) {
cout << b << " ";
if (a <= c) cout << a << " " << c << endl;
else cout << c << " " << a << endl;
}
else {
cout << c << " ";
if (a <= b) cout << a << " " << b << endl;
else cout << b << " " << a << endl;
}
return 0;
}
```
这段代码会先提示用户输入三个实数,再通过if语句判断它们的大小关系并按递增顺序输出。需要注意的是,如果输入的三个实数中有两个或三个相等,那么输出的顺序可能不是严格递增的。
阅读全文