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 <= 1) return n
    return n + f(n - 2)
end function
Print f(9)
  1. A. 25
  2. B. 45
  3. C. 24
  4. D. 16

Correct answer: A. 25

f(9) = 9 + 7 + 5 + 3 + f(1) = 24 + 1 = 25.

More Pseudocode and Code Tracing questions

Exams that ask this topic