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- A. 442
- B. 244
- C. 1004
- 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'.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (/ is integer division.) Function f(Integer n) if (n == 0) return 0 end if return (n…
- What will be the output of the following pseudocode? (/ is integer division.) Integer n = 25, z = 0 while (n > 0) n = n / 5 z = z + n end…
- What will be the output of the following pseudocode? Integer s = 0 for (i = 1 to 30) if (i mod 4 == 0) continue end if if (i mod 7 == 0)…
- What will be the output of the following pseudocode? (Byte variables are 8-bit unsigned: they hold 0–255 and arithmetic wraps modulo 256.)…
- What will be the output of the following pseudocode? (Strings are indexed from 0; swap exchanges two characters.) String s = "ABCDEF"…
- What will be the output of the following pseudocode? Integer c = 0 for (i = 1 to 5) for (j = i to 5) if ((i + j) mod 3 == 0) c = c + 1 end…