#4872. 比较三个数的大小--选择题
比较三个数的大小--选择题
比较三个数的大小,并输出其中最大的数字。如输入3,8,6,输出结果为 8。
判断以下两段代码均可以实现输出三个正整数中最大的数字的效果的说法是否正确。
代码段1:
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
cout<<(a>b?(a>c?a:c):(b>c?b:c));
return 0;
}
代码段2:
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c;
cin >> a >> b >> c;
if(a > b){
if(a > c) cout << a;
else cout << c;
}else{
if(b > c) cout << b;
else cout << c;
}
return 0;
}
{{ select(1) }}
- 对
- 错