Google News
logo
Python Program to Find the LCM of Two Numbers
Here's a Python program to find the LCM (Least Common Multiple) of two numbers :
Program :
def find_lcm(num1, num2):
    # Find the greater number between num1 and num2
    if num1 > num2:
        greater = num1
    else:
        greater = num2
    
    # Loop through multiples of the greater number
    while True:
        if greater % num1 == 0 and greater % num2 == 0:
            lcm = greater
            break
        greater += 1
    
    return lcm

# Example usage
print("LCM of 4 and 6 is", find_lcm(4, 6))
Output :
LCM of 4 and 6 is 12
In this program, the `find_lcm()` function takes two numbers as input parameters and returns their LCM. The function works by finding the greater number between the two, and then looping through multiples of that number until it finds a multiple that is also a multiple of the other number.

This multiple is the LCM of the two numbers.

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