三只小猪称体重
#include<iostream>
using namespace std;
int main(){
int a=0;
int b=0;
int c=0;
cout <<"请输入a的体重:" << endl;
cin>>a;
cout <<"请输入b的体重:" << endl;
cin>>b;
cout <<"请输入c的体重:" << endl;
cin>>c;
if(a>b){ //a比b重
if(a>c){
cout << "a最重"<<endl;
}else{
cout << "c最重"<<endl;
}
}else{ // b比a重
if(b>c){
cout << "b最重"<<endl;
}else{
cout << "c最重"<<endl;
}
}
system("pause");
return 0;
}
三目运算符
#include <iostream>
using namespace std;
int main(){
//三目运算符
int a=10;
int b=20;
int c=2;
c=(a>b?a:b);
cout << "c =" << c<<endl; //c=20
// 三目运算符也可以赋值
(a>b?a:b) = 50;
cout << "a =" << a<<endl; //a=10
cout << "b =" << b<<endl; //b=50
system("pause");
return 0;
}