Even or Odd Flowchart
Flowchart to check even or odd: read n, find the remainder r = n % 2, and ask whether r == 0. With a trace for n = 17, pseudocode, tested Python, C and Java code, and the negative number trap.
Flowchart to check even or odd: read n, find the remainder r = n % 2, and ask whether r == 0. With a trace for n = 17, pseudocode, tested Python, C and Java code, and the negative number trap.
Study guide
A number is even when dividing it by 2 leaves nothing over, and odd when 1 is left over. A flowchart to check even or odd computes that remainder with the % (modulus) operator and asks one question: is it 0?
It is the smallest useful decision flowchart there is, which makes it the perfect first diagram to get exactly right.
n. Input belongs in a parallelogram.n % 2 is the remainder when n is divided by 2. For 17 that is 1, because 17 = 2 x 8 + 1. Storing it in r makes the next diamond easy to read.r == 0, not r == 1: for negative numbers some languages give a remainder of -1, but an even number always gives exactly 0.Follow the flowchart with n = 17, one row per box.
| Step | Box | What happens |
|---|---|---|
| 1 | Read n | n = 17 |
| 2 | Set r = n % 2 | 17 = 2 x 8 + 1, so r = 1 |
| 3 | r == 0? | 1 == 0 is false, so take No |
| 4 | 17 is odd |
Try n = 24 yourself: r = 0, the answer is Yes, and the output is 24 is even.
READ n
r = n MOD 2
IF r = 0 THEN
PRINT n, "is even"
ELSE
PRINT n, "is odd"
ENDIF
n = int(input())
r = n % 2
if r == 0:
print(n, "is even")
else:
print(n, "is odd")
#include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
int r = n % 2; /* -1 for negative odd numbers in C */
if (r == 0) {
printf("%d is even\n", n);
} else {
printf("%d is odd\n", n);
}
return 0;
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int r = n % 2; // -1 for negative odd numbers in Java
if (r == 0) {
System.out.println(n + " is even");
} else {
System.out.println(n + " is odd");
}
}
}
17
17 is odd
All three programs were compiled and run with the input 17 before this page was published, and they print exactly the output shown. In Python -7 % 2 is 1, while in C and Java it is -1. Testing r == 0 gives the right answer in all three.
-7 % 2 is -1, so a flowchart that asks r == 1? calls -7 even. Ask r == 0? instead.n / 2 is the quotient. 17 / 2 is 8 in C and Java, and 8.5 in Python. Neither tells you the parity directly; the remainder does.==. r = 0 is an assignment, and in C it even compiles and gives the wrong answer.0 % 2 is 0, so 0 is even. Zero is an even number.
-6 % 2 is 0 in Python, C and Java alike, so -6 is even. Only odd negatives give a different remainder (1 in Python, -1 in C and Java).
Compute h = n / 2 with whole number division, then ask h * 2 == n?. For 17, h = 8 and 8 x 2 = 16, which is not 17, so 17 is odd.
READ n
h = n DIV 2
IF h * 2 = n THEN
PRINT n, "is even"
ELSE
PRINT n, "is odd"
ENDIF
A counter evens = 0 and a loop that runs 10 times: read n, ask n % 2 == 0?, and on Yes set evens = evens + 1. After the loop, print evens.
The parity diamond sits inside the loop body, the same pattern as the for loop flowchart.
| 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 n and both Print boxes | They move data in or out of the program. |
| Process | Rectangle | Set r = n % 2 | A calculation that stores a value and has one exit. |
| Decision | Diamond | r == 0? | A yes-or-no question with two labelled exits. |
| Flow line | Arrow | Every arrow | Arrows give the order of the steps. |
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 Even or Odd 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.