The below C# program shows how to check a given year is a leap year or not. It's simple logic to check a year is a leap year or not.
using System;
namespace SampleProgram
{
class CheckLeapYear
{
static void Main()
{
// Capture the input
Console.WriteLine("Enter the Year you want to check (in Four Digits): ");
int year = Convert.ToInt32(Console.ReadLine());
// Logic to check leap year
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
{
// Print leap year
Console.WriteLine("{0} is a Leap Year", year);
}
else
{
// Print non leap year
Console.WriteLine("{0} is not a Leap Year", year);
}
Console.ReadKey();
}
}
}
Output:
Enter the Year you want to check (in Four Digits):
2020
2020 is a Leap Year
Comments (0)