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)
  1. A. 26
  2. B. 41
  3. C. 14
  4. D. 40

Correct answer: B. 41

f(0) = 2, f(1) = 5, f(2) = 14, f(3) = 3 x 14 - 1 = 41.

More Pseudocode and Code Tracing questions

Exams that ask this topic