C# Program to Check Year is a Leap Year or Not


-

-

Example:

Copied
using System;

class LeapYear
{
    static void Main(string[] args)
    {
        int year;
        Console.WriteLine("Enter the Year in Four Digits: ");
        year = Convert.ToInt32(Console.ReadLine());
            
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
        {
            Console.WriteLine("{0} is a Leap Year", year);
        }
        else
        {
            Console.WriteLine("{0} is not a Leap Year", year);
        }
            
        Console.ReadLine();
    }
}

Output:

Enter the Year in Four Digits:
2021
2021 is not a Leap Year