# A Python program to find the GCD of two numbers.

Greatest Common Divisor (GCD) is also called as Highest Common Factor(HCF) . The GCD of two positive integers is the largest positive integer that divides both the integers. The following are the example programs to find the gcd of two positive integers using math function, if-else statement, for loop and while loop.

**Ex:** GCD of two positive integers 70 and 18 is 2.

**Steps:**

1. Factors of 70 = 2 x 5 x 7.

2. Factors of 18 = 2 x 3 x 3

3. From the above two factors of ‘2’ is the common divisor. There the gcd(70,18) is ‘2’.

**Finding GCD using math function**

**Output**

The gcd of 70 and 18 is : 2 |

# Finding GCD using if-else

**Output**

Enter X: 175
Enter Y: 49 GCD is: 7 |

**Explanation**

In the above program ‘gcd’ function definition and x and y are the parameters inside it. If y=0 then x is returned. Otherwise x is divided by y and returns y. Then gcd(x,y) ⇒ gcd(175,49) is evaluated and returns 7 as GCD of 175 and 49.

**Finding GCD using for loop.**

**Output**

The gcd of 25 and 7 is : 1 |

# Finding GCD using while loop

**Output**

The gcd of 100 and 68 is : 4 |