Sum from 1 to N flowchart
The most basic loop: add 1 through N. It shows keeping a running total and a counter apart, and how a loop condition becomes a decision.
The diagram
Reading it step by step
- 1. Start at 'Start'.
- 2. 'Read N' is an input or output. Next: 'sum ← 0, k ← 1'.
- 3. 'sum ← 0, k ← 1' is a processing step. Next: 'k ≤ N ?'.
- 4. Decide 'k ≤ N ?': if 'yes', go to 'sum ← sum + k'; if 'no', go to 'Print sum'.
- 5. 'sum ← sum + k' is a processing step. Next: 'k ← k + 1'.
- 6. 'k ← k + 1' is a processing step. Next: 'k ≤ N ?'.
- 7. 'Print sum' is an input or output. Next: 'End'.
- 8. End at 'End'.
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Start | Terminator | → Read N |
| Read N | Input/output | → sum ← 0, k ← 1 · ← Start |
| sum ← 0, k ← 1 | Process | → k ≤ N ? · ← Read N |
| k ≤ N ? | Decision | → sum ← sum + k(yes), Print sum(no) · ← sum ← 0, k ← 1, k ← k + 1 |
| sum ← sum + k | Process | → k ← k + 1 · ← k ≤ N ? |
| k ← k + 1 | Process | → k ≤ N ? · ← sum ← sum + k |
| Print sum | Input/output | → End · ← k ≤ N ? |
| End | Terminator | ← Print sum |
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.
# Sum from 1 to N flowchart
flowchart TD
s(["Start"])
a[/"Read N"/]
b["sum ← 0, k ← 1"]
c{"k ≤ N ?"}
d["sum ← sum + k"]
e["k ← k + 1"]
f[/"Print sum"/]
z(["End"])
s --> a
a --> b
b --> c
c -->|yes| d
d --> e
e --> c
c -->|no| f
f --> z