Skip to content

Commit a44b005

Browse files
committed
compute greatest common factor
1 parent 82f1f33 commit a44b005

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

gcf.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# computes Greatest Common Factor GCF / Greatest Common Divisor GCD of two numbers
2+
# useful for reducing fractions
3+
4+
def gcf (num1, num2):
5+
if num1 > num2:
6+
num1, num2 = num2, num1
7+
8+
for x in range (num1, 0, -1):
9+
if num1 % x == 0 and num2 % x == 0:
10+
return x
11+
12+
num1 = 18
13+
num2 = 204
14+
print (str(gcf(num1, num2)))

0 commit comments

Comments
 (0)