# C# Program to Check if a Given Year is a Leap Year

This is a C# Program to check whether the entered year is a leap year or not.

Problem Description

This C# Program Checks Whether the Entered Year is a Leap Year or Not.

Problem Solution

When A year is divided by 4. If the remainder becomes 0 then the year is called a leap year.

Program/Source Code

Here is source code of the C# Program to Check Whether the Entered Year is a Leap Year or Not. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

```/*
* C# Program to Check Whether the Entered Year is a Leap Year or Not
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Program
{
class leapyear
{
static void Main(string[] args)
{
leapyear obj = new leapyear();
obj.leap();
}
int y;
{
Console.WriteLine("Enter the Year in Four Digits : ");
}
public void leap()
{
if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))
{
Console.WriteLine("{0} is a Leap Year", y);
}
else
{
Console.WriteLine("{0} is not a Leap Year", y);
}
}
}
}```
Program Explanation

In this C# program, we are reading the value of year using ‘year’ variable. When A year is divided by 4. If the remainder becomes 0, then the year is called a leap year.

The Nested-If else condition statement is used to check the given year is leap year or not. In if condition statement the modulus of the value of ‘year’ variable by 4 is equal to 0, and the modulus of the value of ‘year’ variable by 100 is not equal to 0 using logical AND operators.

Otherwise, if the condition is false, then execute the else if condition statement. Compute the modulus of the value of ‘year’ variable by 400 is equal to 0 using logical OR operators. If the condition is true then print the statement as leap year. Otherwise, if the condition is false then execute the else statement. Print the statement as not leap year.

Runtime Test Cases
```
Enter the Year in Four Digits : 1004
1004 is a Leap Year```

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]