ProgrammingModerateTCS NQT · Infosys pattern

What will be the output of the following pseudocode? (/ is integer division; + on strings concatenates.)

What will be the output of the following pseudocode? (/ is integer division; + on strings concatenates.)
Integer n = 100
String s = ""
while (n > 0)
    s = toString(n mod 6) + s
    n = n / 6
end while
Print s
  1. A. 442
  2. B. 244
  3. C. 1004
  4. D. 224

Correct answer: B. 244

Repeated division by 6: 100 = 16·6 + 4, 16 = 2·6 + 4, 2 = 0·6 + 2. Each remainder is PREPENDED, so the digits read 2, 4, 4 → '244' (2·36 + 4·6 + 4 = 100). Appending instead would give '442'.

More Pseudocode and Code Tracing questions

Exams that ask this topic