TechieClues TechieClues
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.
  • 1.2k
  • 0
  • 0

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

TechieClues
TechieClues

I specialize in creating and sharing insightful content encompassing various programming languages and technologies. My expertise extends to Python, PHP, Java, ... For more detailed information, please check out the user profile

https://www.techieclues.com/profile/techieclues

Comments (0)

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