C# 程序查找三个数中的最大值
首先,让我们设置这三个数 −
int num1, num2, num3; // set the value of the three numbers 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;
// set the value of the three numbers
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!
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP