Leap Year Flowchart
Leap year flowchart: test divisible by 400, then by 100, then by 4, in that order. With a trace table for 1900 (the year most answers get wrong), pseudocode, and tested Python, C and Java code.
Leap year flowchart: test divisible by 400, then by 100, then by 4, in that order. With a trace table for 1900 (the year most answers get wrong), pseudocode, and tested Python, C and Java code.
Study guide
In the Gregorian calendar a year is a leap year if it divides by 4, except century years, which must also divide by 400. A leap year flowchart turns that rule into three diamonds, asked from the rarest case (400) to the most common (4).
Order is everything: ask the 400 question first and every later diamond can be a simple yes or no.
year.Follow the flowchart with year = 1900. Each row is one diamond.
| Diamond | Remainder | Answer | Next step |
|---|---|---|---|
| year % 400 == 0? | 1900 % 400 = 300 | No | Go to year % 100 == 0? |
| year % 100 == 0? | 1900 % 100 = 0 | Yes | Print "Not a leap year" |
1900 divides by 4, yet it was not a leap year. A flowchart that only tests by 4 gets this wrong.
READ year
IF year MOD 400 = 0 THEN
PRINT "Leap year"
ELSE IF year MOD 100 = 0 THEN
PRINT "Not a leap year"
ELSE IF year MOD 4 = 0 THEN
PRINT "Leap year"
ELSE
PRINT "Not a leap year"
ENDIF
year = int(input())
if year % 400 == 0:
leap = True
elif year % 100 == 0:
leap = False
elif year % 4 == 0:
leap = True
else:
leap = False
if leap:
print(year, "is a leap year")
else:
print(year, "is not a leap year")
#include <stdio.h>
int main(void) {
int year;
scanf("%d", &year);
int leap;
if (year % 400 == 0) {
leap = 1;
} else if (year % 100 == 0) {
leap = 0;
} else if (year % 4 == 0) {
leap = 1;
} else {
leap = 0;
}
if (leap) {
printf("%d is a leap year\n", year);
} else {
printf("%d is not a leap year\n", year);
}
return 0;
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int year = in.nextInt();
boolean leap;
if (year % 400 == 0) {
leap = true;
} else if (year % 100 == 0) {
leap = false;
} else if (year % 4 == 0) {
leap = true;
} else {
leap = false;
}
if (leap) {
System.out.println(year + " is a leap year");
} else {
System.out.println(year + " is not a leap year");
}
}
}
1900
1900 is not a leap year
All three programs were compiled and run with the input 1900 before this page was published, and they print exactly the output shown. The if, else if chain follows the three diamonds in the same order.
year % 4 == 0? comes first and its Yes goes straight to Leap year, the century rule is never checked. Start with 400, then 100, then 4.2000: 2000 % 400 = 0, Yes, so Leap year (one diamond).
2024: 2024 % 400 = 24, No; 2024 % 100 = 24, No; 2024 % 4 = 0, Yes, so Leap year (three diamonds).
2023: the first two are No as well; 2023 % 4 = 3, No, so Not a leap year.
(year MOD 4 = 0 AND year MOD 100 <> 0) OR year MOD 400 = 0
Divisible by 4 but not by 100, or divisible by 400. It is shorter, but the three diamond version is easier to trace and to mark.
A plain every-4-years rule gives 100 leap days per 400 years, which makes the calendar year a little too long on average. Dropping the century years 1700, 1800 and 1900 (but keeping 2000) removes 3 of them, leaving 97 leap years in each 400.
That is exactly what the 100 and 400 diamonds do.
| Symbol | Shape to draw on paper | Where it appears here | Why |
|---|---|---|---|
| Terminator | Rounded box | Start and End | One entry and one exit. |
| Input/output | Parallelogram | Read year and both Print boxes | They move data in or out of the program. |
| Decision | Diamond | The 400, 100 and 4 tests | Three yes-or-no questions chained on their No exits. |
| Flow line | Arrow | Every arrow | Arrows set the order, which matters most in this flowchart. |
In the interactive diagram every step is a labelled card: the small word above each step names its kind (process, decision or data). When you draw this flowchart by hand, use the standard shapes in the table. The full list is on the flowchart symbols page.
Each link opens the editor with a prompt already filled in. Change the wording, then generate your own flowchart.
Download the Leap Year Flowchart as a PNG or SVG, or open it in the studio to edit your own copy. To draw a similar flowchart from a description, use the flowchart generator; for notation and a step-by-step walkthrough, read how to make a flowchart; and browse more flowchart examples for related layouts.
Type any system, process, or schema in plain English. ChartCraft will draw it in seconds.