ITPEC IP April 2026 Question 8

The procedure findBanknotes outputs the number of 10,000 and 1,000 banknotes required to represent a specified amount of money, in that order, ensuring the minimum number of banknotes is used. The argument amount passed to the procedure must be a non-negative multiple of 1,000. If it is not, the procedure outputs an error message. Which of the following is the correct combination of answers to be inserted into A and B in the program?

[Program]
○ findBanknotes(integer: amount)
integer: tenThousandNote
integer: oneThousandNote
if (amount < 0 or A)
output "Invalid amount"
return
endif
tenThousandNote ← integer part of (amount ÷ 10000)
oneThousandNote ← integer part of (B)
output tenThousandNote, oneThousandNote
OptionAB

Explanation

A: amount mod 1000 ≠ 0, B: (amount mod 10000) ÷ 1000 — reject an amount that is not a multiple of 1,000, then count the thousands left after the 10,000 notes.

The if block prints the error, so its condition must describe an invalid amount: negative, or leaving a remainder when divided by 1,000. That is amount mod 1000 ≠ 0.

Trace a valid amount of 23,000:

  • •A: 23,000 mod 1,000 is 0, so the amount passes the check
  • •tenThousandNote: the integer part of 23000 ÷ 10000 is 2
  • •B: 23,000 mod 10,000 is 3,000, the part not covered by the 10,000 notes, and 3000 ÷ 1000 = 3

Output 2 and 3: 2 × 10000 + 3 × 1000 = 23000 with five notes.

Answer (c)

Why not others:

  • •(a) — B is right, but A is the validity condition itself, so every multiple of 1,000 prints "Invalid amount" and 23,500 goes through
  • •(b) — reverses A in the same way, and its B also counts the whole amount in thousands
  • •(d) — A is right, but B, amount ÷ 1000, gives 23 one-thousand notes for 23,000 on top of the 2 ten-thousand notes: the 20,000 is counted twice, 43,000 in all

Key rule: To break an amount into denominations, integer-divide by the largest to get its count, then take the remainder (mod) before dividing by the next; an error guard tests the negation of the validity rule.

Algorithm and Programming · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official IP past-paper collection or Report an issue.