ProgrammingModerateTCS NQT · Infosys · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
function f(Integer n)
if (n == 0) return 2
return 3 * f(n - 1) - 1
end function
Print f(3)- A. 26
- B. 41
- C. 14
- D. 40
Correct answer: B. 41
f(0) = 2, f(1) = 5, f(2) = 14, f(3) = 3 x 14 - 1 = 41.
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 x = 5, y, z y = x++ 2 z = ++x + y Print x, y, z
- What will be the output of the following pseudocode? Integer s = 0 for (each i from 1 to 10) if (i mod 3 == 0) continue if (i > 8) break s…
- What will be the output of the following pseudocode? Integer r r = (12 AND 10) OR (5 XOR 3) Print r
- What will be the output of the following pseudocode? Integer x = 3 x = x << 2 x = x + (x >> 1) Print x
- What will be the output of the following pseudocode? String s = "PROGRAM", t = "" for (each i from 0 to length(s) - 1) if (i mod 2 == 1) t…
- What will be the output of the following pseudocode? Integer i = 1, c = 0 while (i <= 20) i = i 2 c = c + 1 end while Print i, c