C#程序查找三个数字中的最大值
首先,让我们设置三个数字-
int num1, num2, num3; //设置三个数字的值 num1 = 10; num2 = 20; num3 = 50;
现在检查第一个数字和第二个数字。如果num1>num2,则用num3检查num1。如果num1大于num3,则表示最大数量为num1。
示例
您可以尝试运行以下代码来查找三个数字的最大值。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
class MyApplication {
static void Main(string[] args) {
int num1, num2, num3;
//设置三个数字的值
num1 = 10;
num2 = 20;
num3 = 50;
if (num1 > num2) {
if (num1 > num3) {
Console.Write("Number one is the largest!\n");
} else {
Console.Write("Number three is the largest!\n");
}
}
else if (num2 > num3)
Console.Write("Number two is the largest!\n");
else
Console.Write("Number three is the largest!\n");
}
}
}输出结果
Number three is the largest!
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西