Flowcharts

Flowcharts and algorithm logic

Use these sections when the task is about ordered blocks, loops, or decisions and you need a clear build order.

Main idea

Read the block order first, then draw the flowchart. Use the test values to check the logic.

Method

How to read these flowcharts

The point of this page is not fancy theory. It is to help you rebuild a task block by block.

For each task, read the block order, sketch the main variables, and then draw the flowchart in your editor.

Start simple

Write the input and output blocks first.

Then loop

Add the loop only after the start values are clear.

Then test

Try the sample values listed under each task.

Flowchart

Greeting flowchart test

Use this tiny task when you want to remember the basic shape of a flowchart.

Track: FlowchartsUse blocks, not code

Block order

  1. Start
  2. Output: 'Hello'
  3. Input: read the user's name
  4. Output: 'Hello, name'
  5. End

Useful reminder

This task is good for the very first PS Diagram lesson.

Quick test

  • The diagram should have exactly one input block and two output blocks.
  • The second output must use the value from the input block.
Flowchart

Digit sum

The main idea is to take the last digit, add it, remove it, and repeat.

Track: FlowchartsUse blocks, not code

Block order

  1. Start
  2. Input: number
  3. Set sum = 0
  4. While number > 0
  5. digit = number % 10
  6. sum = sum + digit
  7. number = number / 10
  8. Output sum
  9. End

Useful reminder

Use integer division when you remove the last digit.

Quick test

  • For 528 the sum should be 15.
  • The loop must stop when the number becomes 0.
Flowchart

Reverse text

This flowchart is about index order. You start at the end and move left.

Track: FlowchartsUse blocks, not code

Block order

  1. Start
  2. Input: text
  3. Set result = empty string
  4. Set i = length of text - 1
  5. While i >= 0
  6. Add text[i] to result
  7. Decrease i by 1
  8. Output result
  9. End

Useful reminder

When you draw the loop, show both the index variable and the result string clearly.

Quick test

  • abc should become cba.
  • An empty string should stay empty.
Flowchart

Reverse number

This is similar to digit sum, but you build a new number instead of a sum.

Track: FlowchartsUse blocks, not code

Block order

  1. Start
  2. Input: number
  3. Set reversed = 0
  4. While number > 0
  5. digit = number % 10
  6. reversed = reversed * 10 + digit
  7. number = number / 10
  8. Output reversed
  9. End

Useful reminder

The multiplication by 10 must happen before you add the next digit.

Quick test

  • 1234 should become 4321.
  • 120 should become 21 if leading zeroes are ignored.
Flowchart

Sequence minimum and occurrence count

This is a common pattern: store the current best value, then update a counter.

Track: FlowchartsUse blocks, not code

Block order

  1. Start
  2. Input: count of numbers
  3. Read the first number and set it as min
  4. Set occurrenceCount = 1
  5. Repeat for the remaining numbers
  6. If value < min, set min = value and occurrenceCount = 1
  7. Else if value == min, increase occurrenceCount
  8. Output min and occurrenceCount
  9. End

Useful reminder

The first number is often handled before the loop so you have a valid starting minimum.

Quick test

  • For 4, 2, 2, 9 the minimum is 2 and the count is 2.
  • If the first value is already the minimum, the algorithm must still work.
Flowchart

Factorial

This task is just a product loop. Start with 1, not 0.

Track: FlowchartsUse blocks, not code

Block order

  1. Start
  2. Input: n
  3. Set result = 1
  4. Set i = 1
  5. While i <= n
  6. result = result * i
  7. Increase i by 1
  8. Output result
  9. End

Useful reminder

Show the loop condition clearly. A wrong loop start is the most common mistake here.

Quick test

  • 5! should be 120.
  • 0! should stay 1 if you allow zero.
Flowchart

Quadratic equation in flowchart form

The decision blocks are the key part here. One formula leads to three different cases.

Track: FlowchartsUse blocks, not code

Block order

  1. Start
  2. Input: a, b, c
  3. If a == 0, output 'Not quadratic' and stop
  4. Compute discriminant d = b^2 - 4ac
  5. If d < 0, output 'No real roots'
  6. Else if d == 0, compute one root
  7. Else compute two roots
  8. Output the result
  9. End

Useful reminder

Keep formulas inside process blocks and decisions inside diamond blocks.

Quick test

  • Draw one branch for d < 0, one for d == 0, and one for d > 0.
  • Do not forget the extra check for a = 0.
Flowchart

Greatest common divisor

This is one of the cleanest loop-based algorithms for a flowchart.

Track: FlowchartsUse blocks, not code

Block order

  1. Start
  2. Input: a, b
  3. While b != 0
  4. temporary = b
  5. b = a % b
  6. a = temporary
  7. Output a
  8. End

Useful reminder

Many people find it easier when the temporary variable is shown in its own block.

Quick test

  • For 24 and 18 the result should be 6.
  • The loop must stop when b becomes 0.
Flowchart

Decimal to binary

The remainder from each division becomes the next binary digit, but in reverse order.

Track: FlowchartsUse blocks, not code

Block order

  1. Start
  2. Input: decimal number
  3. Set binary = empty string
  4. While number > 0
  5. remainder = number % 2
  6. Put remainder in front of binary
  7. number = number / 2
  8. Output binary
  9. End

Useful reminder

If the input can be 0, add a special case before the loop.

Quick test

  • 13 should become 1101.
  • The remainder must be added at the front, not at the end.
Flowchart

Bubble sort

Bubble sort is not the fastest sort, but it is great for learning loop order and swapping.

Track: FlowchartsUse blocks, not code

Block order

  1. Start
  2. Input: list of values
  3. Repeat for pass = 0 to length - 2
  4. Repeat for i = 0 to length - 2 - pass
  5. If value[i] > value[i + 1], swap them
  6. After all passes, output the sorted list
  7. End

Useful reminder

If you draw a swap in one block, write it as temporary = a, a = b, b = temporary.

Quick test

  • 3, 1, 2 should end as 1, 2, 3.
  • The inner loop should get shorter after each pass.