GCD of Two Numbers in Python Using Recursion

(Last Updated On: 28/11/2022)

Python Program to Get GCD of Two Numbers Using Recursion

# GCD of Two Numbers in Python Using Recursion

def gcd(a,b):
	if(b==0):
    	return a
	else:
    	return gcd(b,a%b)

# we are taking a number from user as input
# entered value will be converted to int from string
a=int(input("Enter first number:"))
b=int(input("Enter second number:"))

GCD=gcd(a,b)
print("GCD is: ",GCD)

Output:

Enter first number:15
Enter second number:20
GCD is:  5