Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a1a2cf

Browse files
committed
simple gcd algorithm added
0 parents  commit 3a1a2cf

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

Basic/gcd.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Find the greatest common denominator of two numbers
2+
# using Euclid's algorithm
3+
4+
5+
def gcd(a, b):
6+
while (b != 0):
7+
t = a # set aside the value of a
8+
a = b # set a equal to b
9+
b = t % b # divide t (which is a) by b
10+
11+
return a
12+
13+
14+
# try out the function with a few examples
15+
print(gcd(60, 96)) # should be 12
16+
print(gcd(20, 8)) # should be 4

0 commit comments

Comments
 (0)