三目运算符

This commit is contained in:
flykhan 2023-06-19 16:55:34 +08:00
parent a53db5f59b
commit 3b1774ccab
1 changed files with 21 additions and 0 deletions

21
day6/d13.cpp Normal file
View File

@ -0,0 +1,21 @@
// 三目运算符
// 从键盘输入三个整数,输出最大或最小的那个数
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
int x, y, z;
cout << "请输入三个整数: ";
cin >> x >> y >> z;
int max = x > y ? (x > z ? x : z) : (y > z ? y : z);
cout << "最大值为: " << max << endl;
int min = x < y ? (x < z ? x : z) : (y < z ? y : z);
cout << "最小值为: " << min << endl;
return 0;
}