C# program to take a year as input and tells whether it's a leap year or not
Following program shows you how take a year as input and tells whether it's a leap year or not.
using System;
class MainClass {
public static void Main (string[] args) {
Console.WriteLine("Enter a year:");
int input = Convert.ToInt32(Console.ReadLine());
if (input % 4 == 0) {
if (input % 100 == 0) {
if (input % 400 == 0) {
Console.WriteLine(input + " its a leap year");
} else {
Console.WriteLine(input + " its not a leap year");
}
} else {
Console.WriteLine(input + " its a leap year");
}
} else {
Console.WriteLine(input + " its not a leap year");
}
}
}
Output:
Example1:
Enter a year:
2020
2020 its a leap year
Example2:
Enter a year:
2030
2030 its not a leap year