LCM Of Two Numbers In Python Using Recursion

(Last Updated On: 22/11/2022)

Python Program to Find LCM Of Two Numbers Using Recursion

# LCM Of Two Numbers In Python Using Recursion

# Function definition
def findgcd(a, b):   
	if(b == 0):
    	return a;
	else:
     	# Recursion takes place here
    	return findgcd(b, a % b)

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

 #function call
gcd = findgcd(num1, num2)  
lcm = (num1 * num2) // gcd
#Print Result
print('LCM is:',lcm)

Output:

Enter the first number:5
Enter the second number:10
LCM is: 10

Leave a Reply

Your email address will not be published. Required fields are marked *