ProgrammingVery hardProduct company OA · code-tracing level
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
// 32-bit signed integers; overflow wraps around (two's complement)
Integer f = 1
for (each i from 1 to 13)
f = f * i
end for
Print f- A. 6227020800
- B. 1932053504
- C. -1932053504
- D. 479001600
Correct answer: B. 1932053504
12! = 479 001 600 still fits in 32 bits, but 13! = 6 227 020 800 does not. Wrapping keeps the value modulo 2³² = 4 294 967 296: 6 227 020 800 − 4 294 967 296 = 1 932 053 504, which is below 2³¹, so it is printed as a positive number. 6227020800 ignores the overflow; 479001600 is 12!; the negative option assumes every overflow produces a negative result.
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? Integer a = 100, b = 7, steps = 0 while (a != b) if (a > b) a = a - b else b = b - a…
- What will be the output of the following pseudocode? (/ is integer division; calls counts every call, including the first.) Integer calls…
- What will be the output of the following pseudocode? (^ is bitwise XOR and >> is a right shift.) Integer g = 59, n = 0 while (g > 0) n = n…
- How many times does the body of this loop run? // c is an 8-bit unsigned integer: it holds 0 to 255 and arithmetic wraps modulo 256…
- What will be the output of the following pseudocode? (/ is integer division.) Integer a = 7, b = 3 a = a b - a / b Print a
- What will be the output of the following pseudocode? Integer c = 0 for (i = 1 to 20) if (i mod 3 == 0 or i mod 5 == 0) c = c + 1 end if…