Pseudo-code · Question 12 · Hard
What will be the output of the following pseudocode?
Integer fun(Integer n)
if (n < 3)
return n
end if
return fun(n - 1) + fun(n - 3)
End function fun()
Print fun(7)
- 7
- 13
- 10
- 9
Answer and explanation
Answer: C. 10
Explanation: fun(0) = 0, fun(1) = 1, fun(2) = 2. Then fun(3) = 2 + 0 = 2, fun(4) = 2 + 1 = 3, fun(5) = 3 + 2 = 5, fun(6) = 5 + 2 = 7 and fun(7) = 7 + 3 = 10.
Previous: What will be the output of the following pseudocode? (Note: / denotes integer… · Next: What will be the output of the following pseudocode? (Note: &, | and ^ are…
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?
- What will be the output of the following pseudocode? (Note: << and >> are…
- What will be the output of the following pseudocode? (Note: / denotes integer…
- What will be the output of the following pseudocode? (Note: &, | and ^ are…
- What will be the output of the following pseudocode? (Note: for-loop bounds…
- What will be the output of the following pseudocode? (Note: array indices…
- What will be the output of the following pseudocode? (Note: / denotes integer…
- What will be the output of the following pseudocode? (Note: for-loop bounds…
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode?
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