Which of the following flowcharts is most appropriate for printing the first 8…

2022

Which of the following flowcharts is most appropriate for printing the first 8 multiples of 9?

Attempted by 726 students.

Show answer & explanation

Concept: Every counted loop is defined by four parts — an initial value, a continuation test, a body, and an update. Which values such a loop emits is fixed by three independent choices: where the counter starts, whether the test boundary is inclusive (I ≤ limit) or exclusive (I < limit), and whether the update runs before or after the output step. Change any one of them and the emitted list changes, even though every box on its own still looks arithmetically fine.

Application: The target is exactly eight numbers — 9 × 1 up to 9 × 8, that is 9, 18, 27, 36, 45, 54, 63, 72. The most reliable way to guarantee exactly eight outputs is to count iterations rather than values:

  1. Initialise the counter: I = 1.

  2. Test the continuation condition I ≤ 8; if it is false, stop.

  3. Print 9 × I. The print comes before the update, so the first number printed is 9 × 1 = 9.

  4. Update the counter: I = I + 1.

  5. Return to the test and repeat until it fails.

Trace: I takes the values 1, 2, 3, 4, 5, 6, 7, 8, so the printed list is 9, 18, 27, 36, 45, 54, 63, 72 — eight numbers, ending exactly at 72.

Cross-check — trace each flowchart shown:

Flowchart as drawn

Numbers printed

Count

I = 1, test I ≤ 8, print 9 × I, then I = I + 2

9, 27, 45, 63

4

I = 9, test I < 72, print I, then I = I + 9

9, 18, 27, 36, 45, 54, 63

7

I = 9, test I ≤ 72, then I = I + 9, print I

18, 27, 36, 45, 54, 63, 72, 81

8

I = 1, test I ≤ 8, print 9 × I, then I = I + 1

9, 18, 27, 36, 45, 54, 63, 72

8

Building the multiples by addition is not the problem: Generating the multiples by repeated addition (I = I + 9) is a perfectly sound strategy, and an addition is indeed cheaper than a multiplication — cost is not what separates these flowcharts. The addition version drawn with the exclusive test I < 72 fails only at its boundary: when I reaches 72 the test is already false, so the loop exits before that last value is ever printed and only seven numbers appear. Make that test inclusive (I ≤ 72), keeping the print before the update, and the addition version would print the same eight numbers. The other addition variant updates before it prints, which slides the whole output window one step forward, so it starts at 18 and ends at 81.

Result: The flowchart that initialises I = 1, tests I ≤ 8, prints 9 × I and then steps I = I + 1 is the one that prints 9, 18, 27, 36, 45, 54, 63, 72.

Explore the full course: Bpsc

Loading lesson…