ProgrammingModerateAccenture · Capgemini

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 1
    end if
    return f(n - 1) + f(n - 2)
end function
Print f(7)
  1. A. 13
  2. B. 34
  3. C. 8
  4. D. 21

Correct answer: D. 21

f(0) = f(1) = 1 gives 1, 1, 2, 3, 5, 8, 13, 21, so f(7) = 21.

More Pseudocode and Code Tracing questions

Exams that ask this topic