{"id":7486,"date":"2021-09-30T10:30:35","date_gmt":"2021-09-30T05:00:35","guid":{"rendered":"https:\/\/python-programs.com\/?p=7486"},"modified":"2021-11-22T18:35:33","modified_gmt":"2021-11-22T13:05:33","slug":"python-program-to-find-the-lcm-of-two-numbers","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-the-lcm-of-two-numbers\/","title":{"rendered":"Python Program to Find the LCM of Two Numbers"},"content":{"rendered":"

Our website provided core java programs examples with output<\/a> aid beginners and expert coders to test their knowledge gap and learn accordingly.<\/p>\n

We’ll learn how to find the LCM of two numbers in Python programming in this tutorial.<\/p>\n

LCM:<\/strong><\/p>\n

What exactly does LCM stand for? The Least Common Multiple of two numbers is referred to as LCM. The LCM of two numbers a and b, for example, is the lowest positive integer divisible by both.<\/p>\n

Given two numbers a and b , the task is to write the program which calculates lcm of a and b in Python.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

a= 23\u00a0 \u00a0b=12<\/pre>\n

Output:<\/strong><\/p>\n

The LCM of the given two numbers 23 , 12 = 276<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

a= 18 b=72<\/pre>\n

Output:<\/strong><\/p>\n

The LCM of the given two numbers 18 , 72 = 72<\/pre>\n

Example3:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

a= 4 b=8<\/pre>\n

Output:<\/strong><\/p>\n

The LCM of the given two numbers 4 , 8 = 8<\/pre>\n

Example4:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

a= 9 b=9<\/pre>\n

Output:<\/strong><\/p>\n

The LCM of the given two numbers 9 , 9 = 9<\/pre>\n

Explanation:<\/strong><\/p>\n

 The least common divisor of two numbers is number itself if both the numbers are equal<\/pre>\n

Program to Calculate LCM of Two numbers in Python<\/h2>\n

There are several ways to calculate the lcm of two numbers in Python some of them are:<\/p>\n

    \n
  • Using while loop<\/a><\/li>\n
  • Using GCD\/HCF of the given two numbers<\/a><\/li>\n
  • Using Numpy lcm function.<\/a><\/li>\n<\/ul>\n

    Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n