Pseudo-code · Question 26 · Medium
What will be the output of the following pseudocode?
Integer fun(Integer n)
if (n <= 1)
return 1
end if
return fun(n - 1) + 2 * fun(n - 2)
End function fun()
Print fun(5)
- 11
- 15
- 43
- 21
Answer and explanation
Answer: D. 21
Explanation: fun(0) = fun(1) = 1, so fun(2) = 3, fun(3) = 5, fun(4) = 11 and fun(5) = 11 + 2 × 5 = 21.
Previous: What will be the output of the following pseudocode? (Note: &, ^ and >> are… · Next: What will be the output of the following pseudocode? (Note: array indices…
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: array indices…
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode? (Note: &, ^ and >> are…
- What will be the output of the following pseudocode? (Note: array indices…
- What will be the output of the following pseudocode?
- 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