Programming Constructs and Operators: Question 1

Syllabus 8.1

Multiple choice 1 mark

A conference organiser uses this pseudocode to work out how many minibuses are needed to transport delegates to a venue. Each minibus seats exactly 9 people.

DECLARE Delegates : INTEGER
DECLARE FullBuses : INTEGER
DECLARE Remaining : INTEGER
Delegates ← 47
FullBuses ← Delegates DIV 9
Remaining ← Delegates MOD 9
OUTPUT FullBuses, " full minibuses and ", Remaining, " delegates left over"

What is output when this algorithm is run?

Choose an answer to check it, then compare with the worked solution below.

Show worked solution Hide worked solution

Worked solution

Step 1: Recall what DIV and MOD do

In Cambridge pseudocode, for two integers A and B:

  • A DIV B gives the whole number of times B divides into A, with any remainder discarded (integer division, always rounded down towards zero for positive integers).
  • A MOD B gives the remainder left over after A DIV B whole groups of B have been removed from A.

Both operators use the same two operands, Delegates (47) and 9, so they must be worked out from the same pair of numbers.

Step 2: Work out FullBuses

FullBuses ← Delegates DIV 9

Find the largest whole number of 9s that fit into 47:

  • 9 × 5 = 45 (fits, since 45 is less than or equal to 47)
  • 9 × 6 = 54 (too big, since 54 is greater than 47)

So 47 DIV 9 = 5. There are 5 complete minibuses.

Step 3: Work out Remaining

Remaining ← Delegates MOD 9

This is what is left over after removing those 5 complete groups of 9:

47 - (5 × 9) = 47 - 45 = 2

So 47 MOD 9 = 2. There are 2 delegates left over after filling the 5 full minibuses.

Step 4: Confirm the output

The OUTPUT statement prints FullBuses, the fixed text " full minibuses and ", Remaining, then " delegates left over". Substituting the traced values gives:

5 full minibuses and 2 delegates left over

Step 5: Why the other options are wrong

  • Option B (6 full minibuses and 2 delegates left over) comes from doing ordinary division, 47 ÷ 9 = 5.22, and rounding this up to 6, but DIV truncates rather than rounds, so it must give exactly 5, not 6.
  • Option C (2 full minibuses and 5 delegates left over) comes from swapping the two operators: computing FullBuses with MOD (giving 2) and Remaining with DIV (giving 5). The pseudocode clearly assigns DIV to FullBuses and MOD to Remaining.
  • Option D (5 full minibuses and 47 delegates left over) comes from misunderstanding MOD as simply returning the original value of Delegates unchanged, instead of the true remainder of 2 after 5 whole groups of 9 have been removed.

Final answer

  • The algorithm outputs “5 full minibuses and 2 delegates left over”, option A.