ProgrammingModerateCapgemini · Infosys pattern

What will be the output of the following pseudocode? (All variables are integers, so / is integer division.)

What will be the output of the following pseudocode? (All variables are integers, so / is integer division.)
Integer a = 15, b = 4
Print (a / b) * b + a mod b
  1. A. 12
  2. B. 3
  3. C. 16
  4. D. 15

Correct answer: D. 15

a / b = 3, so 3 × 4 + 15 mod 4 = 12 + 3 = 15. For integers, (a / b) × b + a mod b always gives back a.

More Pseudocode and Code Tracing questions

Exams that ask this topic