Open csp256 opened 4 years ago
non-recursive... def nonr_gcd(a,b):
if a<b:
a+=b
b=a-b
a-=b
if (b==0):
return a
while (a % b != 0):
a+=b
b=a-b
a-=b
b%=a
return b
thing = nonr_gcd(20, 462) print(thing)
def it_gcd(a, b): while b != 0: j = b b = a % b a = j return a
print(it_gcd(45, 697080))
Assignment to
inp_{a,b}
in function is unnecessary.Should this function return a value or print it?
Can you write it in an iterative, non-recursive form?