Python Program to Find GCD of Two Numbers using Recursion

Python Program to Find GCD of Two Numbers using Recursion

Write Python Program to Find GCD of Two Numbers using Recursion – Method 1

# Write Python Program to Find GCD of Two Numbers using Recursion

def gcd(n, m):
    if n == m:
        return n
    elif n < m:
        return gcd(m, n)
    else:
        return gcd(m, n - m)
    

n = 72
m = 32
ans = gcd(n, m)
print(f'GCD of {n} and {m} : {ans}')

Output:

GCD of 72 and 32 : 8