Python program to find LCM of the given 3 numbers

Hello everyone, welcome to nkcoderz.com. In this article we will going to discuss about Python program to find LCM of the given 3 numbers.

Code for python program to find LCM of the given 3 numbers

def lcm(a, b, c):
    # Find the greatest common divisor of the three numbers
    def gcd(x, y):
        while y:
            x, y = y, x % y
        return x

    # Find the LCM of the three numbers
    lcm = (a*b*c)//(gcd(a,gcd(b,c)))
    return lcm

# Test the function
print(lcm(5, 7, 9))

Output

315

Explanation

The program defines a function lcm that takes in three numbers as arguments (a, b, and c). Inside the lcm function, there is another function called gcd which finds the greatest common divisor of two numbers by using Euclidean algorithm.

Then LCM is calculated using the formula (abc)//(gcd(a,gcd(b,c))) which ensures the LCM is found of 3 numbers by the concept of transitive property of GCD and LCM.

Python program to check the given number is Adam’s number

Conclusion

If you liked this post, then please share this with your friends and make sure to bookmark this website for more awesome content.


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment