Skip to content

Commit 4e41b3f

Browse files
authored
Create GCD.py
1 parent 5cc90d1 commit 4e41b3f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pygorithm/math/GCD.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def find_gcd(x, y):
2+
3+
while(y):
4+
x, y = y, x % y
5+
6+
return x
7+
8+
9+
l = [2, 4, 6, 8, 16]
10+
11+
num1 = l[0]
12+
num2 = l[1]
13+
gcd = find_gcd(num1, num2)
14+
15+
for i in range(2, len(l)):
16+
gcd = find_gcd(gcd, l[i])
17+
18+
print(gcd)

0 commit comments

Comments
 (0)