In this C# program, we will learn how to write a program to check whether the entered year is a leap year or not.
Here is the code of the program to check whether the entered year is a leap year or not:
using System;
namespace Tutorialsrack
{
class Program
{
/* C# Program to Check Whether the Entered Year is a Leap Year or Not */
static void Main(string[] args)
{
Console.Write("Enter the Year in Four Digits: ");
int 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.ReadKey();
}
}
}
Enter the Year in Four Digits: 2016
2016 is a Leap Year
Enter the Year in Four Digits: 2014
2014 is not a Leap Year
Comments