Find the maximum: algorithm flowchart
Finds the largest of N numbers: take the first as the maximum, then compare the rest one by one. A classic loop exercise in programming classes.
The diagram
Reading it step by step
- 1. Start at 'Start'.
- 2. 'Read N numbers' is an input or output. Next: 'max ← first number, i ← 2'.
- 3. 'max ← first number, i ← 2' is a processing step. Next: 'i ≤ N ?'.
- 4. Decide 'i ≤ N ?': if 'yes', go to 'number i > max ?'; if 'no', go to 'Print max'.
- 5. Decide 'number i > max ?': if 'yes', go to 'max ← number i'; if 'no', go to 'i ← i + 1'.
- 6. 'max ← number i' is a processing step. Next: 'i ← i + 1'.
- 7. 'i ← i + 1' is a processing step. Next: 'i ≤ N ?'.
- 8. 'Print max' is an input or output. Next: 'End'.
- 9. End at 'End'.
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Start | Terminator | → Read N numbers |
| Read N numbers | Input/output | → max ← first number, i ← 2 · ← Start |
| max ← first number, i ← 2 | Process | → i ≤ N ? · ← Read N numbers |
| i ≤ N ? | Decision | → number i > max ?(yes), Print max(no) · ← max ← first number, i ← 2, i ← i + 1 |
| number i > max ? | Decision | → max ← number i(yes), i ← i + 1(no) · ← i ≤ N ? |
| max ← number i | Process | → i ← i + 1 · ← number i > max ? |
| i ← i + 1 | Process | → i ≤ N ? · ← max ← number i, number i > max ? |
| Print max | Input/output | → End · ← i ≤ N ? |
| End | Terminator | ← Print max |
Symbols used here
| Symbol | Meaning |
|---|---|
| Terminator | Where the flow starts or ends; a rounded rectangle. |
| Process | One action such as a calculation; a 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.
# Find the maximum: algorithm flowchart
flowchart TD
s(["Start"])
a[/"Read N numbers"/]
b["max ← first number, i ← 2"]
c{"i ≤ N ?"}
d{"number i > max ?"}
e["max ← number i"]
g["i ← i + 1"]
h[/"Print max"/]
z(["End"])
s --> a
a --> b
b --> c
c -->|yes| d
d -->|yes| e
e --> g
d -->|no| g
g --> c
c -->|no| h
h --> z