 # Python Program to Find the GCD of Two Numbers

Python program to find the gcd of two numbers; Through this tutorial, you will learn how to find the greatest common divisor (GCD) of the two numbers or array elements in the Python program using for loop, function.

GCD of two or more non-zero number is the largest number that divides both or more non-zero numbers. It is one of the basic concepts of mathematics.

## Python Program to Find the GCD of Two Numbers

• Python program to find the GCD of two non-zero numbers
• Python program to find the GCD of the array

### Python program to find the GCD of two non-zero numbers

• Allow user to input numbers.
• Include math module.
• Calculate gcd by using math.gcd() function and store result in variable.
• Print result.
```#Python | Program to Find the GCD of the Array

# import math module
import math

# input two numbers
m,n=map(int,input('Enter two non-zero numbers: ').split())

#to find GCD
g=math.gcd(m,n)

# printing the result
print('GCD of {} and {} is {}.'.format(m,n,g))

```

Output

```Enter two non-zero numbers:  5 10
GCD of 5 and 10 is 5.```

In the above python gcd program, you have learned to find the GCD of two non-zero number.

Now we will find the GCD of an array element or more than two non-zero numbers. So, let’s go to write a Python program by simply using the above-given python program concepts.

### Python program to find the GCD of the array

```#Python | Program to Find the GCD of the Array

# importing the module
import math

# array of integers
A=[100,150,250,150,170,110,195]

#initialize variable b as first element of A
b=A
for j in range(1,len(A)):
s=math.gcd(b,A[j])
b=s
print('GCD of array elements is  {}.'.format(b))
```

Output

GCD of array elements is 5.

## Recommended Python Programs 