Pseudo-code · Question 8 · Medium
What will be the output of the following pseudocode?
Integer fun(Integer n)
if (n <= 0)
return 1
end if
return fun(n - 2) + n
End function fun()
Print fun(7)
- 16
- 18
- 15
- 17
Answer and explanation
Answer: D. 17
Explanation: fun(-1) = 1, so fun(1) = 1 + 1 = 2, fun(3) = 2 + 3 = 5, fun(5) = 5 + 5 = 10 and fun(7) = 10 + 7 = 17.
Previous: What will be the output of the following pseudocode? (Note: for-loop bounds… · Next: What will be the output of the following pseudocode?
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: / 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?
- 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?
- 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…
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