Here you will find an algorithm and program in C# programming language to check whether the given year is leap year or not. First let us understand what is leap year?
Explanation : A leap year is a calendar year that contains an additional day added to keep the calendar year synchronized. A leap year is exactly divisible by 4, except for the century years (the years ending with 00). Century year is a leap year only if it is completely divisible by 400.
For Example : 2012 is Leap Year, 2014 is not a leap year.
Leap Year Algorithm
START
Step 1 → Initialize variable year
Step 3 → Check if year is divisible by 4 but not by 100, DISPLAY "leap year"
Step 4 → Check if year is divisible by 400, DISPLAY "leap year"
Step 5 → Otherwise, DISPLAY "not leap year"
STOP
C# Program to Check Leap Year
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.readdata();
obj.leap();
}
int check_year;
public void readdata()
{
check_year = 1998;
}
public void leap()
{
if ((check_year % 4 == 0 && check_year % 100 != 0) || (check_year % 400 == 0))
{
Console.WriteLine("{0} is a Leap Year", check_year);
}
else
{
Console.WriteLine("{0} is not a Leap Year", check_year);
}
Console.ReadLine();
}
}
}
Output
1998 is not a leap year.