[15102 views]

There are 365 days in a year. A leap year is a year that has 366 days, instead of 365 days. Hence, a leap year has one day extra and occurs every four years. We can check whether a given year is a leap year or not with the following logic. We usually think that a leap year will be divisible by 4, but apart from this, there are other conditions to do this checking. A year will be a leap year only if:

•It is divisible by 4 and not divisible by 100

•It is divisible by 400

Let us consider an example:

2020/4 = 505.

Therefore, 2020 is a leap year.

2000/100 = 20, 2000/400 = 5 and 2000/4 = 500.

Therefore, 2000 is a leap year.

2022/4 = 505.5

Therefore, 2022 is not a leap year.

Let us have a look at the algorithm and flowchart to check whether a given year is a leap year or not.

We start off by taking the value of the year to be checked as user input and store it in a variable say, ‘year’. To check whether the given year is a leap year or not, we will have to check whether the value is divisible by 4 or not. If it is divisible by 4, we must check whether that value is divisible by 100. It will be a leap year only if it is divisible by 4 and not divisible by 100. If the previous condition is not satisfied, we check whether the value is divisible by 400. If any one of the given conditions is true for the value, the year will be a leap year, otherwise, it will not be a leap year.

We check these conditions for the value with the help of the statement: If (year%4 = 0 AND year%100 != 0) OR year%400 = 0. Here, we use the modulus operator to check for divisibility. If this condition holds true, then we display a message saying that the year is a leap year, else we display that the year is not a leap year.

Note: Here ‘%’ is the modulus operator which returns the remainder value after division.

**Example: **

Let us consider the year 2000:

year = 2000

2000 % 400 = 0

Therefore, 2000 is a leap year.

Let us consider the year 2000:

year = 2007

year / 4 = 2007 / 4 = 501

2007 % 4 = 3

2007 % 400 = 7

Therefore, 2007 is not a leap year.

Liked Article? Please Buy me a Tea 😭 |

- Algorithm and Flowchart to find all the factors of an Integer
- Postfix to Prefix notation Algorithm and Flowchart
- Algorithm and Flowchart to find the Maximum Absolute Difference Among the given Array
- Algorithm and Flowchart to Swap Two Integer Numbers with and without third variable
- Algorithm and Flowchart to Find Area of Square