C++ program to check leap year

C++ program to check leap year
All years which are perfectly divisible by 4 are leap years except for century years (years ending with 00) which is leap year only it is perfectly divisible by 400. A year that is divisible by 4 is known as a leap year. However, years divisible by 100 are not leap years while those divisible by 400 are.

In this program below, user is asked to enter a year and this program checks whether the year entered by user is leap year or not.

Some of the leap years are :
2012, 2004, 1968 etc are leap year but, 1971, 2006 etc are not leap year.
Similarly, 1200, 1600, 2000, 2400 are leap years but, 1700, 1800, 1900 etc are not.

The pseudo code is to check leap year is

if year is divisible by 400 then is_leap_year
else if year is divisible by 100 then not_leap_year
else if year is divisible by 4 then is_leap_year
else not_leap_year

Example#5.0: C++ program to check leap year without function:



Output

Enter a year : 2016
2016 is a leap year.


Example#5.1: C++ program to check leap year using function:



Output

Enter a year : 2016
2016 is a leap year.

Post a Comment

Previous Post Next Post