IGCSE · Practice questions · Library routines: MOD, DIV, ROUND and RANDOM

Quotient and remainder.

Six original Cambridge-style questions on library routines in 0478 pseudocode, with mark points.

Original questions All questions on this page are original work, written in the Cambridge IGCSE style. They are not from past papers. They test the same concepts and skills the syllabus rewards.
Keep these straight

Divide, then split.

01
Recall
[2 marks]

State what is returned by the library routines DIV and MOD.

  • DIV returns the quotient of a division with the fractional part discarded (a whole number). ✓
  • MOD returns the remainder of the division. ✓
02
Calculate
[4 marks]

State the value returned by: (a) DIV(29, 4) (b) MOD(29, 4) (c) ROUND(29 / 4, 0) (d) ROUND(12.3456, 2)

  • (a) 7 ✓
  • (b) 1 ✓
  • (c) 29 / 4 = 7.25, which rounds to 7 ✓
  • (d) 12.35 ✓
03
Write
[3 marks]

Write pseudocode that inputs a number of seconds and outputs it as minutes and seconds, using DIV and MOD.

  • INPUT Seconds ✓
  • Mins ← DIV(Seconds, 60) and Secs ← MOD(Seconds, 60) ✓
  • OUTPUT Mins, " minutes ", Secs, " seconds" ✓
04
Write
[3 marks]

Write a statement that stores a random whole number from 1 to 100 in the variable Target. Explain why your expression cannot give 0 or 101.

  • Target ← ROUND(RANDOM() * 99, 0) + 1 ✓
  • ROUND(RANDOM() * 99, 0) gives a whole number from 0 to 99. ✓
  • Adding 1 gives 1 to 100, so 0 and 101 are impossible. ✓
05
Apply
[3 marks]

Write pseudocode that inputs a whole number and outputs "Even" or "Odd".

  • INPUT Number ✓
  • IF MOD(Number, 2) = 0 ✓
  • THEN OUTPUT "Even" ELSE OUTPUT "Odd" with ENDIF ✓
06
Analysis
[2 marks]

A student tests whether Number is even with IF Number / 2 = 0. Explain why this does not work and correct it.

  • Number / 2 is the result of the division, which is only 0 when Number is 0; it is not the remainder. ✓
  • Correct: IF MOD(Number, 2) = 0. ✓

Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.