Even or odd flowchart
Uses the remainder after dividing by 2 to tell even from odd. The simplest branch: one decision, two paths, one end.
The diagram
Reading it step by step
- 1. Start at 'Start'.
- 2. 'Read integer n' is an input or output. Next: 'n mod 2 = 0 ?'.
- 3. Decide 'n mod 2 = 0 ?': if 'yes', go to 'Print even'; if 'no', go to 'Print odd'.
- 4. 'Print even' is an input or output. Next: 'End'.
- 5. End at 'End'.
- 6. 'Print odd' is an input or output. Next: 'End'.
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Start | Terminator | → Read integer n |
| Read integer n | Input/output | → n mod 2 = 0 ? · ← Start |
| n mod 2 = 0 ? | Decision | → Print even(yes), Print odd(no) · ← Read integer n |
| Print even | Input/output | → End · ← n mod 2 = 0 ? |
| Print odd | Input/output | → End · ← n mod 2 = 0 ? |
| End | Terminator | ← Print even, Print odd |
Symbols used here
| Symbol | Meaning |
|---|---|
| Terminator | Where the flow starts or ends; a rounded rectangle. |
| Decision | A question whose answer picks the next path; a diamond. |
| Input/output | Data comes in or goes out; a parallelogram. |
| Flow line | The order of steps, in the arrow direction. |
Diagram text
Paste this text into the editor to get the same picture, then change the names to fit your own work.
# Even or odd flowchart
flowchart TD
s(["Start"])
a[/"Read integer n"/]
b{"n mod 2 = 0 ?"}
c[/"Print even"/]
d[/"Print odd"/]
z(["End"])
s --> a
a --> b
b -->|yes| c
b -->|no| d
c --> z
d --> z