Python program to find lcm of two numbers
In this programming article, we will learn to write:
-
program to find lcm of two numbers in python
Program to find LCM of two numbers in Python
The python program to find lcm of two numbers is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
n1 = int(input("Enter the first number: "))
n2 = int(input("Enter the second number: "))
if n1 > n2:
greater = n1
else:
greater = n2
while(True):
if(greater % n1 == 0 and greater % n2 == 0):
lcm = greater
break
greater += 1
print("The LCM is:",lcm)
The output of program to find lcm of two numbers in python using while loop is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter the first number: 3
Enter the second number: 4
The LCM is: 12
Few important points about this program:
1. The LCM i.e. Lowest Common Multiple is the smallest number which can be divided by both the numbers.
2. We take the greater number, find whether it can be divided by itself and the other number. If so, then that number is the LCM, else we increment the number to find the number.
Given below is snapshot to write a python program to find lcm of two numbers:
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :
Jan 30,2021