程序在C ++中使用三元运算符查找最大数
为此,我们将提供两个数字。我们的任务是找出其中最大的数字,并使用三元运算符将其打印出来。
示例
#include <stdio.h>
int main() {
int n1 = 5, n2 = 10, n3 = 15, max;
//寻找最大
max = (n1 > n2) ? (n1 > n3 ? n1 : n3) : (n2 > n3 ? n2 : n3);
printf("Largest number among %d, %d and %d is %d.", n1, n2, n3, max);
return 0;
}输出结果
Largest number among 5, 10 and 15 is 15.
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便