먼저, 세 개의 숫자를 설정하겠습니다 -
int num1, num2, num3; // set the value of the three numbers num1 = 10; num2 = 20; num3 = 50;
이제 첫 번째 숫자와 두 번째 숫자를 확인하십시오. num1> num2이면 num1과 num3을 확인합니다. num1이 num3보다 크면 가장 큰 숫자가 num1임을 의미합니다.
예시
다음 코드를 실행하여 최대 3개의 숫자를 찾을 수 있습니다.
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!\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!