ProgrammingHardAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Function f(Integer n)
    if (n > 100)
        return n - 10
    end if
    return f(f(n + 11))
End Function

Print f(50)
  1. A. 91
  2. B. 90
  3. C. 101
  4. D. 51

Correct answer: A. 91

This is McCarthy's 91 function. For any n ≤ 100 the nested calls climb above 100 and come back down to 91. For example f(100) = f(f(111)) = f(101) = 91, and every smaller n reduces to f(100).

More Pseudocode and Code Tracing questions

Exams that ask this topic