首先,让我们设置三个数字-
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!