Python Program

LCM HCF | Python LCM and HCF | 1 Easy to understand

LCM and HCF(GCD) are the terminology you might have seen in your school level math. You might have heard these two things earlier and now we will try to solve them programatically.

For more python tutorials visit our playlist and also visit python programs page here.

HCF (Highest Common Factor) and GCD (Greatest Common Divisor) are the same thing. HCF is the term commonly used in British English, while GCD is the term commonly used in American English. Both terms refer to the same concept of finding the largest positive integer that divides each of the given numbers without leaving any remainder.

For example, the HCF (or GCD) of 12 and 18 is 6, because 6 is the largest number that divides both 12 and 18 without leaving any remainder.

In programming languages such as Python, the term GCD is commonly used instead of HCF. However, the two terms refer to the same concept and can be used interchangeably.

Consider the input

num1 = 12
num2 = 30

LCM (Least Common Multiple) :

print("The LCM of", num1,"and", num2,"is", calculate_lcm(num1, num2))
def calculate_lcm(x, y):
    lcm = (x*y)//calculate_hcf(x,y)
    return lcm

HCF (Highest Common Factor) :

print("The HCF of", num1,"and", num2,"is", calculate_hcf(num1, num2))
def calculate_hcf(x, y):
    while(y):
        x, y = y, x % y
    return x

For more python tutorials visit our playlist and also visit python programs page here.

Abhishek

Share
Published by
Abhishek

Recent Posts

5G and 6G Technology Advancements: A Promising Future of Connectivity

5G and 6G Technology AdvancementsWhat is 5G, and How Has It Transformed Connectivity?1. Understanding 5G…

2 weeks ago

HTML: The Evolution and Power of Unleashed Web Language and Modern too

IntroductionInitial StagesEvolutionChallenging Other LanguagesCurrent TrendsAI and HTMLConclusion Introduction HTML, or HyperText Markup Language, is the…

4 months ago

Increase in 80C in Budget 2024 ?

Increase in 80CDemands and Discussions: Increase in 80C Section 80C of the Income Tax Act…

4 months ago

ChatGPT 4o Unleashing the Power of GPT A Comprehensive Guide

IntroductionWhat is ChatGPT-4?Key Features of ChatGPT-4Enhanced Natural Language UnderstandingImproved Response GenerationVersatilityApplications of ChatGPT-4Customer SupportContent CreationEducational…

6 months ago

APJ Abdul Kalam Biography: A Tribute to India’s Powerful Missile Man

APJ Abdul Kalam Biography :Childhood :Academics :Professional Career :Achievements : APJ Abdul Kalam Biography :…

9 months ago

Srinivasa Ramanujan Biography: Exploring the Genius

We value your feedback! Please share your thoughts on this blog on Srinivasa Ramanujan Biography…

10 months ago

This website uses cookies.