Solution 6 to 12
Solution 10

Leap Years in a Range

This program finds and lists all leap years within a user-defined range. Leap years are those which are divisible by 4, but not by 100 unless they are also divisible by 400. The user is prompted to input a starting and ending year, and the program will display all leap years between these two values.

Code Breakdown

Algorithm

  1. Start
  2. Input the starting year and ending year.
  3. For each year in the range from the starting year to the ending year:
    • Check if the year is a leap year:
      • A year is a leap year if it is divisible by 4 and not divisible by 100 or it is divisible by 400.
    • If the year is a leap year, print the year.
  4. End

Code Explanation

Example Flowchart

                             Start
                               |
                               V
                  Input the start and end years
                               |
                               V
                +-------------------------------+
                |  For each year in the range   |
                |  (from start to end):         |
                |  - Check if the year is a     |
                |    leap year using the rules: |
                |    - Divisible by 4 AND not   |
                |      divisible by 100, OR     |
                |      divisible by 400         |
                +-------------------------------+
                               |
                               V
               Print the year if it is a leap year
                               |
                               V
                              End