# GCD of Two Numbers in Python using For loop

ADVERTISEMENTS

GCD of two numbers in __python__ using for loop. In this article, you will learn how to find the gcd of two numbers in python using for loop.

## What is GCD of Two Numbers?

The

**GCD**is the largest integer number of two positive integer numbers that can exactly divide both numbers without remaining a remainder.

## GCD of Two Numbers in Python using While loop

```
# GCD of Two Numbers in Python using While loop
p, q = None, None
# p & q - denotes the two positive numbers
print ("-----Enter the two positive integer numbers-----")
p = int (input ())
q = int (input ())
while p != q:
if p > q:
p -= q
else:
q -= p
print ("\nThe GCD number is: ", p)
```

### Output

`-----Enter the two positive integer numbers-----`

160

70

`The GCD number is: 10`

## GCD of Two Numbers in Python using For loop

```
# GCD of Two Numbers in Python using For loop
p, q, g = None, None, None
# p & q - denotes the two positive numbers
print ("-----Enter the two positive integer numbers-----")
p = int (input ())
q = int (input ())
for i in range (1, p + 1):
if i <= q:
if p % i == 0 and q % i == 0:
g = i
print ("\nThe GCD number of ", p, " & ", q, " is: ", g)
```

### Output

`-----Enter the two positive integer numbers-----`

160

70

`The GCD number of 160 & 70 is: 10`