ProgrammingHardCapgemini · Infosys pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Function fact(Integer n)
    if (n <= 1)
        return 1
    end if
    return n * fact(n - 1)
End Function

Print fact(6)
  1. A. 120
  2. B. 720
  3. C. 360
  4. D. 6

Correct answer: B. 720

fact unwinds as 6*fact(5), recursively multiplying down to the base case fact(1)=1, giving the full product 6*5*4*3*2*1 = 720.

More Pseudocode and Code Tracing questions

Exams that ask this topic