Google News
logo
Python Program to Find the LCM of Two Numbers using Recursion
Here's a Python program to find the LCM (Least Common Multiple) of two numbers using recursion :
Program :
def find_gcd(num1, num2):
    if num2 == 0:
        return num1
    else:
        return find_gcd(num2, num1 % num2)

def find_lcm(num1, num2):
    lcm = (num1 * num2) // find_gcd(num1, num2)
    return lcm

# Example usage
print("LCM of 12 and 18 is", find_lcm(12, 18))
Output :
LCM of 12 and 18 is 36
In this program, the `find_gcd()` function takes two numbers as input parameters and returns their GCD. The `find_lcm()` function takes two numbers as input parameters and returns their LCM.

The function first calculates the product of the two numbers and then divides it by their GCD to get the LCM.

The program prints the LCM of 12 and 18 as an example. You can replace these numbers with any two integers to find their LCM.