Created
April 23, 2013 02:32
-
-
Save PatchRowcester/5440375 to your computer and use it in GitHub Desktop.
Iterative way to calculate the GCD of two numbers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gcdIter(a,b): | |
x = min(a,b) | |
for i in range(min(a,b)): | |
if a%x==0 and b%x==0: | |
break | |
else: | |
x -= 1 | |
return x | |
print('This is a program to calculate the GCD of two integers.') | |
a = int(raw_input('Enter first number: ')) | |
b = int(raw_input('Enter second number: ')) | |
z = gcdIter(a,b) | |
print('The GCD of the two numbers is: ' + str(z)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment