ProgrammingHardAccenture · Capgemini
What will be the output of the following pseudocode? (All variables are integers, so / is integer division; + joins strings)
What will be the output of the following pseudocode? (All variables are integers, so / is integer division; + joins strings)
String digits = "0123456789ABCDEF", r = ""
Integer n = 2024
while (n > 0)
r = digits[n mod 16] + r
n = n / 16
end while
Print r- A. 8E7
- B. 7D8
- C. 7E8
- D. 7E9
Correct answer: C. 7E8
2024 = 7 × 256 + 14 × 16 + 8, so the hexadecimal digits are 7, E, 8: 7E8. Appending instead of prepending would give the reversed 8E7.
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? (code(c) gives a letter's character code and char(k) the reverse) String s =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; arrays are indexed from 0)…
- What will be the output of the following pseudocode? Integer c = 0 for (each i from 1 to 10) for (each j from 1 to i) if (j j > i) break…
- What will be the output of the following pseudocode? Integer m[3][3] = {{5, 1, 7}, {2, 9, 3}, {8, 4, 6}} Integer c = 0 Boolean peak for…
- What will be the output of the following pseudocode? String s = "CODE IS FUN", r = "", w = "" for (each i from 0 to length(s) - 1) if…
- What will be the output of the following pseudocode? (substring(t, i, k) is the k characters starting at index i; indices start at 0)…