Find HCF and LCM using Python

[4396 views]


In this article, we will implement very simple Python Program to Find HCF and LCM of a given number.

Find HCF and LCM of a given number using Python
from functools import reduce def gcd(a,b): while b: a,b=b,a%b return a def lcm(a,b): return a*b//gcd(a,b) a = [int(i) for i in input().split()] print(reduce(gcd,a)) print(reduce(lcm,a)) ######################################## from math import gcd as g print(reduce(g,a))
        

Don't Understand Algorithm and Flowchart? Learn quickly using our Expert's Notes



Want to get in-depth understanding of Algorithms?


Are You Good enough in Algorithms? Test it now?


Comments



Search
Recommended Deals End in










Java Interview Questions For Beginner Notes
Quiz for Learners
Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Search Tags

    HCF and LCM simple implementation in Python

    Python program for HCF and LCM

    Calculate HCF and LCM using Python