Pseudo-code · Question 22 · Medium
What will be the output of the following pseudocode?
Integer fun(Integer a, Integer b)
if (b == 0)
return a
end if
return fun(b, a mod b)
End function fun()
Print fun(84, 36)
- 252
- 4
- 12
- 6
Answer and explanation
Answer: C. 12
Explanation: This is Euclid's algorithm: fun(84, 36) -> fun(36, 12) -> fun(12, 0), which returns 12, the GCD of 84 and 36.
Previous: What will be the output of the following pseudocode? (Note: for-loop bounds… · 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?
- 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? (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?
- 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…
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