Created
September 26, 2016 17:57
-
-
Save devils-ey3/39c5812f4cc345883d92b196835f1e3d to your computer and use it in GitHub Desktop.
Write an iterative function, gcdIter(a, b), that implements this idea. One easy way to do this is to begin with a test value equal to the smaller of the two input arguments, and iteratively reduce this test value by 1 until you either reach a case where the test divides both a and b without remainder, or you reach 1.
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): | |
""" | |
make a program thake return | |
largest integer divides of two number | |
without using reminder or % syntex""" | |
if b<a: | |
a,b = b,a | |
c = a | |
while c>0: | |
if (a/c==a//c) and (b/c==b//c): | |
return c | |
c-=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment