ProgrammingVery hardInfosys SP · Goldman Sachs OA

What will be the output of the following pseudocode? (All variables are integers, so / is integer division)

What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
Function f(Integer n)
    if (n == 0)
        return 1
    end if
    return f(n / 2) + f(n / 3)
End Function
Print f(12)
  1. A. 13
  2. B. 12
  3. C. 21
  4. D. 8

Correct answer: B. 12

Build up: f(0) = 1, f(1) = 2, f(2) = 3, f(3) = 4, f(4) = 5, f(6) = 7, f(12) = f(6) + f(4) = 7 + 5 = 12.

More Pseudocode and Code Tracing questions

Exams that ask this topic