程序填空题:三个数排序 - C/C++ 分支与循环
请编程实现下述功能:
从键盘读入三个整数a,b和c(0≤a,b,c≤100);要求这三个整数从同一行录入,以逗号分隔;
仅使用分支语句(不允许交换)确定三个数的顺序,并将三个数从小到大输出,数间以逗号分隔。
![image.png](~/14bafc49-6116-4a22-b042-896933524a5f.png)
[3个数的比较排序树]
说明:椭圆形表示一次两数比较,矩形结点表示一个排序结果。
请参考上图,将下述程序补充完整。
#include <iostream>
using namespace std;
int main(){
int a {0}, b{0}, c{0};
cin >> a >> b >> c;
if (a<=b) {
if (b<=c)
else {
if
cout << a << "," << c << "," << b;
else
}
}
else{
if (a<=c)
cout << b << "," << a << "," << c;
else {
if
cout << c << "," << b << "," << a;
}
}
return 0;
}
### 感觉不会? 那试着听听**免费的B站网课**
[简洁的C和C++ - 重庆大学在线课程](https://www.bilibili.com/video/BV1it411d7zx/)
[Python编程基础及应用 - 重庆大学在线课程](https://www.bilibili.com/video/BV1kt411R7uW/)
![image.png](~/6e79c9e3-cb7f-486d-ab78-36b5a8f655c0.png)
答案:
第1空:cout << a << "," << b << "," << c;
第2空:(a<=c)
第3空:cout << c << "," << a << "," << b;
第4空:(b<=c)
第5空: cout << b << "," << c << "," << a;
第6空:else
从键盘读入三个整数a,b和c(0≤a,b,c≤100);要求这三个整数从同一行录入,以逗号分隔;
仅使用分支语句(不允许交换)确定三个数的顺序,并将三个数从小到大输出,数间以逗号分隔。
![image.png](~/14bafc49-6116-4a22-b042-896933524a5f.png)
[3个数的比较排序树]
说明:椭圆形表示一次两数比较,矩形结点表示一个排序结果。
请参考上图,将下述程序补充完整。
#include <iostream>
using namespace std;
int main(){
int a {0}, b{0}, c{0};
cin >> a >> b >> c;
if (a<=b) {
if (b<=c)
else {
if
cout << a << "," << c << "," << b;
else
}
}
else{
if (a<=c)
cout << b << "," << a << "," << c;
else {
if
cout << c << "," << b << "," << a;
}
}
return 0;
}
### 感觉不会? 那试着听听**免费的B站网课**
[简洁的C和C++ - 重庆大学在线课程](https://www.bilibili.com/video/BV1it411d7zx/)
[Python编程基础及应用 - 重庆大学在线课程](https://www.bilibili.com/video/BV1kt411R7uW/)
![image.png](~/6e79c9e3-cb7f-486d-ab78-36b5a8f655c0.png)
答案:
第1空:cout << a << "," << b << "," << c;
第2空:(a<=c)
第3空:cout << c << "," << a << "," << b;
第4空:(b<=c)
第5空: cout << b << "," << c << "," << a;
第6空:else