Structured programming notes
3. Nested Control Structures
3.4. Examples of flowchart
1. What is a Flowchart?
A flowchart is a diagrammatic representation of an algorithm or process.
-
It uses symbols to represent different steps.
-
Helps visualize the flow of control, especially in structured programming.
Common symbols:
| Symbol | Meaning |
|---|---|
| Oval / Ellipse | Start or End |
| Rectangle | Process / Action |
| Diamond | Decision / Selection (Yes/No) |
| Parallelogram | Input / Output |
| Arrows | Flow of control |
2. Examples of Flowchart Descriptions
Example 1: Find the largest of two numbers
Description: The program reads two numbers and prints the largest one.
Flowchart Steps:
-
Start (Oval)
-
Input number A and number B (Parallelogram)
-
Decision: Is A > B? (Diamond)
-
Yes: Print A (Rectangle)
-
No: Print B (Rectangle)
-
-
End (Oval)
Explanation:
-
The diamond represents selection, choosing which number to print.
-
The flowchart clearly shows the decision and the flow to the end.
Example 2: Print even numbers from 1 to 5
Description: The program prints only even numbers from 1 to 5 using a loop.
Flowchart Steps:
-
Start (Oval)
-
Set
i = 1(Rectangle) -
Decision: Is
i <= 5? (Diamond)-
No: Go to End
-
Yes: Continue
-
-
Decision: Is
i MOD 2 = 0? (Diamond)-
Yes: Print i (Parallelogram)
-
No: Skip printing
-
-
Increment
i = i + 1(Rectangle) -
Go back to Step 3 (loop)
-
End (Oval)
Explanation:
-
Combines iteration (loop from 1 to 5) and selection (print only if even).
-
Flowcharts make loops and decisions visually clear.
Example 3: Sum positive numbers until zero is entered
Description: Keep reading numbers, sum the positive ones, and stop when 0 is entered.
Flowchart Steps:
-
Start (Oval)
-
Set
sum = 0(Rectangle) -
Input number (Parallelogram)
-
Decision: Is number = 0? (Diamond)
-
Yes: Go to Step 6 (End)
-
No: Continue
-
-
Decision: Is number > 0? (Diamond)
-
Yes: Add number to sum (Rectangle)
-
No: Skip addition
-
-
Go back to Step 3 (loop)
-
Output sum (Parallelogram)
-
End (Oval)
Explanation:
-
Iteration: Loop continues until 0 is entered.
-
Selection: Only positive numbers are added.
-
Flowchart shows decision-making and repetition clearly.