연도를 입력했을때, if문을 이용해서 윤년이면 1, 아니면 0을 출력하는 문제이다.
문제에서의 윤년 조건은
- 윤년은 연도가 4의 배수이면서
- 100의 배수가 아닐때
- 또는 400의 배수일 때
윤년의 조건을 if문으로 작성해주면 된다.
using System;
public class MainClass {
public static void Main() {
string value = Console.ReadLine();
int year = Convert.ToInt32(value);
if (year>=1 && year<=4000)
{
if (CheckValue(year))
{
Console.WriteLine(1);
}
else
{
Console.WriteLine(0);
}
}
}
private static bool CheckValue(int year)
{
bool result = false;
if ((year%4)==0)
result = true;
else
result = false;
if (result)
{
if ((year%100) == 0)
{
result = false;
}
if ((year%400) == 0)
{
result = true;
}
}
return result;
}
}
|
cs |
'C#' 카테고리의 다른 글
[백준] 10817번 세 수 C# 풀이 (0) | 2019.09.24 |
---|---|
[백준] 2884번 알람 시계 C# 풀이 (0) | 2019.09.24 |
[백준] 9498번 시험성적 C# 풀이 (0) | 2019.09.21 |
[백준] 1330번 두 수 비교하기 C# 풀이 (0) | 2019.09.21 |
[DataGridView] 마지막 행 없애기 (0) | 2019.04.21 |