C# 程序查找三个数字中的最大值
csharpserver side programmingprogramming更新于 2025/9/23 23:42:00
首先,让我们设置三个数字的减号
int num1, num2, num3; // 设置三个数字的值 num1 = 10; num2 = 20; num3 = 50;
现在用第二个数字检查第一个数字。如果 num1 > num2,则用 num1 检查 num3。如果 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!
");
} else {
Console.Write("Number three is the largest!
");
}
}
else if (num2 > num3)
Console.Write("Number two is the largest!
");
else
Console.Write("Number three is the largest!
");
}
}
}
输出
Number three is the largest!

