Python Program to find LCM

You are Here:

What is Least Common Multiple?

A smallest common multiple of two or more integers.

In general, Least Common Multiple (LCM) is otherwise called as Lowest Common Multiple (LCM) or Smallest Common Multiple (SCM)

Tips: It is recommended to use our online LCM calculator for better understanding.

Examples

The following table provides few examples of LCM of the given numbers.

NumbersLCM
4, 1020
6, 530
15, 30 , 4590

LCM of Two Numbers

n the following example, we will find the LCM of the given two numbers (45, 90).

Example

Python Compiler
num1 = 45 num2 = 90 max = (num1 > num2) and num1 or num2 while(1): if((max % num1 == 0) and (max % num2 == 0)): print("LCM of %d and %d: %d" % (num1, num2, max)); break max += 1

Output

LCM of 45 and 90: 90

LCM of any Two Given Numbers

In the following example, we will find the LCM of any two given numbers.

Example

Python Compiler
num1 = int(input("Enter (int) num1 = ")) num2 = int(input("Enter (int) num2 = ")) max = (num1 > num2) and num1 or num2 while(1): if((max % num1 == 0) and (max % num2 == 0)): print("\nLCM of %d and %d: %d" % (num1, num2, max)); break max += 1

Output

Enter (int) num1 = 24 Enter (int) num2 = 48 LCM of 24 and 48: 48

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on Python with examples for quick and easy learning.

We are working to cover every Single Concept in Python.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author