In: Computer Science
Using python pls!!!!! Write a recursive function gcd(m,n) that returns the greatest common divisor of a pair of numbers. The gcd of m and n is the largest number that divides both m and n. If one of the numbers is 0, then the gcd is the other number. If m is greater than or equal to n, then the gcd of m and n is the same as the gcd of n and m-n. If n is greater than m, then the gcd is the same as the gcd of m and n-m.
Pls endevour to use recursive approach to this
CODE:
def gcd(m,n):
# if m is Zero return n
if(m==0):
return n
# if n is zero retun m
elif(n==0):
return m
# if m is greater than or equal to n call gcd(n,m-n)
elif(m>=n):
return gcd(n,m-n)
# if n is greater than m then call gcd(m,n-m)
else:
return gcd(m,n-m)
SAMPLE TEST CODE:
SAMPLE OUTPUT:
EXPLANATION:
Two Numbers taken as input from prompt and GCD of the Numbers is displayed on the next line.