So I have written
function gcd(a, b)
if b <> 0
gcd (b, a % b)
else
return a
print gcd (12, 9)
so it goes:
- gcd(12, 9)
- 9 <> 0 means TRUE
- gcd(9, 12 % 9 = 3)
- 3 <> 0 means TRUE
- gcd(3, 9 % 3 = 0)
- 0 <> 0 means FALSE
- return a which is 3 but it returns nothing
Could you please help me find my mistake?
I think you need this line:
instead of just:
Here’s my Python code showing the solution in action:
This was with Python 2.4.3 on Linux.