83,700 views
23 votes
23 votes
Write a function gcdRecur(a, b) that implements this idea recursively. This function takes in two positive integers and returns one integer.

''def gcdRecur(a, b):
'''
a, b: positive integers
returns: a positive integer, the greatest common divisor of a & b.
'''
# Your code here
if b == 0:
return a
else:
return gcdRecur(b, a%b)
#Test Code
gcdRecur(88, 96)
gcdRecur(143, 78)
© 2021 GitHub, Inc.

User Delyan
by
2.3k points

1 Answer

16 votes
16 votes

Answer & Explanation:

The program you added to the question is correct, and it works fine; It only needs to be properly formatted.

So, the only thing I did to this solution is to re-write the program in your question properly.

def gcdRecur(a, b):

if b == 0:

return a

else:

return gcdRecur(b, a%b)

gcdRecur(88, 96)

gcdRecur(143, 78)

User Can Nguyen
by
2.6k points