Pseudo-code · Question 28 · Hard
What will be the output of the following pseudocode?
Integer fun(Integer n)
if (n > 50)
return n - 5
end if
return fun(fun(n + 6))
End function fun()
Print fun(40)
- 46
- 51
- 41
- 35
Answer and explanation
Answer: A. 46
Explanation: fun(40) = fun(fun(46)). For 46 the recursion climbs: fun(46) = fun(fun(52)) = fun(47), and so on up to fun(50) = fun(fun(56)) = fun(51) = 46. So fun(46) = 46 and fun(40) = fun(46) = 46.
Previous: What will be the output of the following pseudocode? (Note: array indices… · Next: What will be the output of the following pseudocode? (Note: for-loop bounds…
Practise pseudo-code
Try a fresh set of pseudo-code questions with an explanation after every answer, free and without signing up: Pseudo-code practice. Or sit a full placement mock test.
More pseudo-code questions
- What will be the output of the following pseudocode? (Note: &, ^ and >> are…
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode? (Note: array indices…
- What will be the output of the following pseudocode? (Note: for-loop bounds…
- What will be the output of the following pseudocode? (Note: for-loop bounds…
More technical & programming practice
C Programming · Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge