Python

# Python Program to Find GCD or HCF of two numbers2 min read

The full form of GCD is ” Greatest Common Divisor”. Which means the greatest common factor of the two numbers. It is also known by the name HCF(Highest common factor). I will be using both the words so don’t confuse yourself.

I have used for loopif-else statement, min() function and break statement.

We have checked both numbers by dividing them every number less than the minimum of both the numbers. And if that number divides both the numbers without leaving any remainder than that number becomes the HCF of the given numbers. And remember that I am running the loop in reverse order.

How to find gcd of two numbers

Output:

## Finding GCD or HCF of two numbers using Euclid’s algorithm in python

In this method, we are going to use Euclid’s algorithm which is much faster. I have used while loopif-else statement, and swapping technique.

Output:

## Finding GCD or HCF of two numbers by Euclid’s algorithm using recursion in python

Here we have made a recursive function gcd().

Output:

In this program, we used many things which I used to make previous programs and also learnt about many other things about python.

Now you can try some other programs. And If you find any problem then you can always contact me or comment below.