Skip to content

Instantly share code, notes, and snippets.

@devils-ey3
Created September 26, 2016 17:57
Show Gist options
  • Save devils-ey3/39c5812f4cc345883d92b196835f1e3d to your computer and use it in GitHub Desktop.
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.
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