程序填空题:三个数排序 - C/C++ 分支与循环
请编程实现下述功能:
从键盘读入三个整数a,b和c(0≤a,b,c≤100);要求这三个整数从同一行录入,以逗号分隔;
仅使用分支语句(不允许交换)确定三个数的顺序,并将三个数从小到大输出,数间以逗号分隔。
[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;
}
答案:
第1空:cout << a << "," << b << "," << c;
第2空:(a<=c)
第3空:cout << c << "," << a << "," << b;
第4空:(b<=c)
第5空: cout << b << "," << c << "," << a;
第6空:else