Program to find hcf of two numbers in Python
In this python program guide, we will learn to write a
program to find hcf of two numbers in python
Python program to find HCF of two numbers
The python program to find hcf of two numbers is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
n1 = int(input("Enter the first number: "))
n2 = int(input("Enter the second number: "))
n1, n2 = n2, n1 % n2
print("The HCF/GCD is:",n1)
The output of the python program to find hcf of two numbers is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter the first number: 54
Enter the second number: 24
The HCF/GCD is: 6
Few important points about this program:
1. To find the HCF or GCD of two numbers here, we are using the Euclidean algorithm here.
2. While the remainder is not becoming equal to zero, we keep on following the steps.
3. We are printing the HCF or GCD at the end.
Given below is screenshot of write a program to find hcf of two numbers in python.
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
Full Stack Web Developer & Data Science Enthusiast
Page Views :
Published Date :