Leap year check
A worked example to adapt. Rename steps, add branches and owners to match how your team actually works.
Mermaid source for this diagram
flowchart TD
s(["Start"])
in[/"Read year Y"/]
d1{"Y mod 4 = 0?"}
d2{"Y mod 100 = 0?"}
d3{"Y mod 400 = 0?"}
ly[/"Print leap year"/]
nl[/"Print not a leap year"/]
e(["End"])
s --> in
in --> d1
d1 -->|Yes| d2
d1 -->|No| nl
d2 -->|Yes| d3
d2 -->|No| ly
d3 -->|Yes| ly
d3 -->|No| nl
ly --> e
nl --> ePaste into any Markdown tool that renders Mermaid, such as GitHub.
About this leap year flowchart
Under the Gregorian calendar a year is a leap year if it is divisible by 4, except that years divisible by 100 are not leap years unless they are also divisible by 400. That is why 2024 and 2000 were leap years and 1900 was not.
The rule has three conditions and one exception to an exception, which makes it a good exercise in ordering decisions. The flowchart checks the most common case first: a year not divisible by 4 is never a leap year and exits immediately. Only years divisible by 4 go on to the century test, and only century years go on to the 400 test.
Students often draw the three conditions in the wrong order, for example testing 400 last on the wrong branch, which marks 1900 as a leap year. Tracing the three test years below catches every common mistake.
Step by step
- Input. Read the year Y.
- Divisible by 4?. If not, Y is not a leap year. Most years exit here.
- Divisible by 100?. If Y is divisible by 4 but not by 100 (like 2024), it is a leap year.
- Divisible by 400?. Century years are leap years only if divisible by 400: 2000 yes, 1900 no.
- Output and end. Print the result. Both outputs lead to the end oval.
How to make it in flow-chart.io
- Start from the example. Press "Use this template" to open this exact leap year flowchart in the editor, or edit the text in the generator box and press Generate for a free preview without signing up.
- Match your program. Rename the input, process and output boxes so they use the same variable names as your code. Keep one action per box.
- Check every branch. Trace each diamond with a test value for the Yes exit and one for the No exit, and make sure both reach the end oval.
- Share or export. Share a read-only view link with a classmate or reviewer. Downloads as PNG, SVG or PDF are part of Flow Pro (see pricing).
Tips
- Trace 2024: divisible by 4 Yes, by 100 No, so leap year. Correct.
- Trace 1900: by 4 Yes, by 100 Yes, by 400 No, so not a leap year. Correct.
- Trace 2000: by 4 Yes, by 100 Yes, by 400 Yes, so leap year. Correct.
- One-line condition: (Y mod 4 = 0 and Y mod 100 ≠ 0) or (Y mod 400 = 0).
- Python: leap = (y % 4 == 0 and y % 100 != 0) or y % 400 == 0.
Frequently asked questions
- What is the rule for a leap year?
- Divisible by 4, except years divisible by 100, which are leap years only if also divisible by 400. This is the Gregorian calendar rule.
- Why is 1900 not a leap year?
- It is divisible by 4 and by 100 but not by 400, so the century exception applies.
- Can the flowchart be drawn with one decision?
- Yes, with a combined condition: (Y mod 4 = 0 and Y mod 100 ≠ 0) or Y mod 400 = 0. Teachers often ask for the three-decision version because it shows the logic step by step.
- Which order should the checks go in?
- Either 4, then 100, then 400 as drawn here, or 400 first, then 100, then 4. Both are correct if each branch leads to the right output; trace 1900 and 2000 to be sure.
- Can I open this flowchart in an editor?
- Yes. Press Use this template to open it in the editor with a free account; every box is editable.