Console Programming/C# Console

5일차 세 개의 정수를 입력받아 두번째로 큰 수 출력 --------코드 수정

폰타인 2019. 9. 24. 13:14

불필요한 코드가 많은 것 같아서 코드를 수정했다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax11
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1, num2, num3;
            Console.Write("입력1 : ");
            num1 = Int32.Parse(Console.ReadLine());
            Console.Write("입력2 : ");
            num2 = Int32.Parse(Console.ReadLine());
            Console.Write("입력3 : ");
            num3 = Int32.Parse(Console.ReadLine());
 
            if (num1 > num2)
            {
                if (num2 > num3)
                {
                    Console.WriteLine(num2);
                }
                else
                {
                    Console.WriteLine(num3);
                }
            }
            else if (num2 > num3)
            {
                if (num3 > num1)
                {
                    Console.WriteLine(num3);
                }
                else
                {
                    Console.WriteLine(num1);
                }
            }
            else if (num3 > num1)
            {
                if (num1 > num2)
                {
                    Console.WriteLine(num1);
                }
                else
                {
                    Console.WriteLine(num2);
                }
            }
            else if (num1 == num2 || num1 == num3)
            {
                Console.WriteLine(num1);
            }
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter