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:

  1. Start (Oval)

  2. Input number A and number B (Parallelogram)

  3. Decision: Is A > B? (Diamond)

    • Yes: Print A (Rectangle)

    • No: Print B (Rectangle)

  4. 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:

  1. Start (Oval)

  2. Set i = 1 (Rectangle)

  3. Decision: Is i <= 5? (Diamond)

    • No: Go to End

    • Yes: Continue

  4. Decision: Is i MOD 2 = 0? (Diamond)

    • Yes: Print i (Parallelogram)

    • No: Skip printing

  5. Increment i = i + 1 (Rectangle)

  6. Go back to Step 3 (loop)

  7. 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:

  1. Start (Oval)

  2. Set sum = 0 (Rectangle)

  3. Input number (Parallelogram)

  4. Decision: Is number = 0? (Diamond)

    • Yes: Go to Step 6 (End)

    • No: Continue

  5. Decision: Is number > 0? (Diamond)

    • Yes: Add number to sum (Rectangle)

    • No: Skip addition

  6. Go back to Step 3 (loop)

  7. Output sum (Parallelogram)

  8. End (Oval)

Explanation:

  • Iteration: Loop continues until 0 is entered.

  • Selection: Only positive numbers are added.

  • Flowchart shows decision-making and repetition clearly.