[C# 제어문 실습 예제 코드] 세 개의 정수를 크기 순으로 출력
[C# 제어문 실습 예제 코드] 세 개의 정수를 크기 순으로 출력
//4.세 개의 정수를 입력받은 후에 크기가 큰 순서부터 출력하는 프로그램을 작성하시오.
using System;
namespace 조건문실습
{
class Program
{
static void Main(string[] args)
{
//세 개(a,b,c)의 정수를 입력
int a, b, c;
Console.WriteLine("첫 번째 수를 입력:");
a = int.Parse(Console.ReadLine());
Console.WriteLine("두 번째 수를 입력:");
b = int.Parse(Console.ReadLine());
Console.WriteLine("세 번째 수를 입력:");
c = int.Parse(Console.ReadLine());
if(a>b)//조건 (a >b)
{
if(a>c) //조건 (a>c)
{
//a가 제일 큰 것은 확정
if(b>c)//조건(b>c)
{
Console.WriteLine("{0}{1}{2}", a, b, c);
}
else//조건(b>c)
{
Console.WriteLine("{0}{1}{2}", a, c, b);
}
}
else//조건 (a>c)
{
//c가 제일 크고 다음은 a
Console.WriteLine("{0}{1}{2}", c, a, b);
}
}
else//if(a>b)
{
if(b>c)//조건(b>c)
{
//b가 제일 큰 것은 확정
if (a > c)
{
Console.WriteLine("{0}{1}{2}", b, a, c);
}
else//(a > c)
{
Console.WriteLine("{0}{1}{2}", b, c, a);
}
}
else//if(b>c)
{
Console.WriteLine("{0}{1}{2}", c, b, a);
}
}
}
}
}