Sabari M Sabari M
Updated date Feb 22, 2021
This 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.

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

ABOUT THE AUTHOR

Sabari M
Sabari M
Software Professional, India

IT professional with 14+ years of experience in Microsoft Technologies with a strong base in Microsoft .NET (C#.Net, ASP.Net MVC, ASP.NET WEB API, Webservices,...Read More

https://www.techieclues.com/profile/alagu-mano-sabari-m

Comments (0)

There are no comments. Be the first to comment!!!
×