Algorithm and flowchart to check whether a given year is a leap year or not





Algorithm and flowchart to check whether a given year is a leap year or not

[83115 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.

Algorithm to check whether a given year is a leap year or not:

Step 1: Start Step 2: Read the value of the year to be checked from the user Step 3: Assign the value to a variable, say ‘year’ Step 4: If (year%4 = 0 AND year%100 != 0) OR year%400 = 0, then: Step 4.1: Display “Leap Year” Step 5: Else Step 5.1: Display “Not Leap Year” Step 6: Stop

Explanation:

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.

Flowchart to check whether a given year is a leap year or not:

Algorithm and flowchart to check whether a given year is a leap year or not
Remove WaterMark from Above Flowchart

                 



Want to Learn How to write own Algorithm and Flowcharts



Want to test your logical skills in Algorithms?



Comments

1 comment
  • Keshav Raj Chaudhary

    Flowchart needs some correction. 2020 is leap year and is divisible by 4 but not by 100. But according to above flowchart, if year is divisible by 4 but not by 100 is not leap year. That's your mistake. Hope you will make correction soon










Search
Have Technical Doubts????


Hot Deals ends in













Technical Quizzes Specially For You:

Search Tags

    Pseudocode to check whether a given year is a leap year or not

    Check if year is a leap year algorithm

    Identify leap year flowchart

    flowchart to check whether the given year is leap year or not

    leap year flowchart

    Leap year Algorithm