백준 백준 BOJ C# 2753

2020. 1. 9. 20:27백준 알고리즘 단계별/if 문

반응형

 

출제 링크 : https://www.acmicpc.net/problem/2753

 

2753번: 윤년

연도가 주어졌을 때, 윤년이면 1, 아니면 0을 출력하는 프로그램을 작성하시오. 윤년은 연도가 4의 배수이면서, 100의 배수가 아닐 때 또는 400의 배수일 때 이다. 예를들어, 2012년은 4의 배수라서 윤년이지만, 1900년은 4의 배수이지만, 100의 배수이기 때문에 윤년이 아니다. 하지만, 2000년은 400의 배수이기 때문에 윤년이다.

www.acmicpc.net

 

코드

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
using System;
using static System.Console;
 
namespace baekjoon
{
    class Program
    {
        
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int num = int.Parse(input);
 
            if (((num % 4== 0&& ((num % 100> 0))
            {
                WriteLine("1");
            }
            else if ((num % 400== 0)
            {
                WriteLine("1");
            }
            else
                WriteLine("0");
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs
반응형