Question 9
Back to Exercise
What is the output of the following Python program?
def gcd(a, b):
return a if b == 0 else gcd(b, a % b)
print(gcd(48, 18), gcd(18, 48), gcd(7, 13), gcd(0, 9))
- A 6 18 1 0
- B 6 6 1 0
- C 18 6 1 9
- D 6 6 1 9 Correct
Correct Answer: Option D
gcd(18, 48) first becomes gcd(48, 18) because 18 % 48 is 18. gcd(0, 9) → gcd(9, 0) → 9.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!