5일차 year를 입력받아 윤년인지 아닌지 판별하기

Console Programming/C# Console 2019. 9. 24. 16:14

연도를 입력받아 윤년인지 아닌지 출력한다.

윤년이 되는 기준은

4의배수 이고 100의 배수가 아닐것

또는

400의 배수일것

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
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)
        {
            Console.WriteLine("연도를 입력하세요. 윤년이면1, 아니면0 이 나옵니다. ");
            int year = Int32.Parse(Console.ReadLine());
 
            if ( (year%4==0 && year%100 !=0|| year%400==0)
            {
                Console.WriteLine(1);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
 
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

: