LCM function

EasyFunction Programs · 15 of 39

Write a Python function to find the LCM of two numbers.

Advertisement
Input
12, 20
Output
60

Approach

  1. LCM = a × b // HCF.

Solution

Python
def hcf(a, b):    while b:        a, b = b, a % b    return a def lcm(a, b):    return a * b // hcf(a, b) print(lcm(12, 20))
Output
60

Learn the concept

New to this topic? Read the lesson, then come back.

More function programs

← All 39 Function Programs

Leave a Comment