Method to Determine Leap Year Algorithm– Eduauraa
Working with dates on a computer can be quite tricky for several reasons.
The presence of leap years makes the task even more difficult. A year has 365 days, but a leap year is comprised of 366 days. The one extra day is added in the February month.
Usually, February has 28 days and is also known as the shortest month of the year. An extra day is added, which gives a total of 29 days in February.
The following section of this article discusses the different steps of developing a program to help users tell whether a given year is a leap year.
Over the years, the calendars in use have changed significantly. At present, we use the Gregorian calendar that was first introduced in the year 1582. Here the task is to prepare a program that will read the year as an integer and then display whether it is a leap year or not.
Algorithm for Leap Year
Every year that is divisible bi fore is considered as a leap year.
On the other hand, uses that are exactly divisible by 100 are not considered leap years.
If the centurial years are exactly divisible by 400, it is termed as a leap year.
Years like 1700, 1800, 1900 are not categorized as leap years, but years 1600, 2000 are leap years. Following is the algorithm of creating a program that will find a leap year.
Psedudo algorithm for finding whether a year is a leap year or not:
Step 1- Take an integer variable
Step 2- Assign values to the variable
Step 3- Check whether a year is divisible by four but not with hundred and print leap year.
Step 4- Check if a year is divisible by four hundred and print leap year
Step 5- Otherwise, print not leap year
This is how one can determine whether a year is a leap year or not with the help of an algorithm.
The algorithm has conditions for the divisibility test of 4, 100, and 400. It analyses the code, and then the divisibility is checked using a single if or multiple if-else conditions.
Either way, the programs give the same output.