ProgrammingVery hardProduct company OA
What will be the output of the following pseudocode? (calls counts every call of f, including the first.)
What will be the output of the following pseudocode? (calls counts every call of f, including the first.)
Integer calls = 0
Function f(Integer n)
calls = calls + 1
if (n > 100)
return n - 10
end if
return f(f(n + 11))
End Function
Print f(99), calls- A. 91 3
- B. 100 5
- C. 91 5
- D. 89 3
Correct answer: C. 91 5
f(99) → f(f(110)); f(110) = 100. Then f(100) → f(f(111)); f(111) = 101. Then f(101) = 91. Calls: f(99), f(110), f(100), f(111), f(101) = 5, result 91 (this is McCarthy's 91 function: every n ≤ 100 gives 91). '89' applies n − 10 to 99 directly.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (/ is integer division; the division in the loop is always exact.) Integer n = 10, c…
- What will be the output of the following pseudocode? ('ref' parameters are passed by reference; ^ is bitwise XOR; arrays are indexed from…
- What will be the output of the following pseudocode? (Arrays are passed by reference and indexed from 0.) Procedure p(Integer arr[]…
- What will be the output of the following pseudocode? (/ is integer division.) Integer c = 0, i = 1, j while (i < 1000) j = i while (j > 0)…
- What will be the output of the following pseudocode? (/ is integer division.) Integer c = 0 for (n = 1 to 200) Integer s = 0, t = n while…
- What will be the output of the following pseudocode? (isComposite[] starts all false; ops counts every assignment inside the inner loop…