ProgrammingModerateTCS NQT · Accenture

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Function odd(Integer n)
    if (n == 0)
        return 0
    end if
    return odd(n - 1) + 2 * n - 1
End Function
Print odd(12)
  1. A. 156
  2. B. 78
  3. C. 144
  4. D. 169

Correct answer: C. 144

odd(n) adds the first n odd numbers 1 + 3 + … + (2n − 1), which equals n². odd(12) = 144.

More Pseudocode and Code Tracing questions

Exams that ask this topic