Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. def gcdIter(a, b):
  2. '''
  3. a, b: positive integers
  4.  
  5. returns: a positive integer, the greatest common divisor of a & b.
  6. '''
  7. # Your code here
  8.  
  9. global x
  10. global y
  11. if a>=b:
  12.  
  13. x=a
  14. y=b
  15. else:
  16. x=b
  17. y=a
  18. if x%y==0:
  19. return y
  20.  
  21. else:
  22.  
  23. while x%y>=0 or y%y>=0:
  24. y=y-1
  25.  
  26. if a%y==0 and b%y==0:
  27.  
  28. return y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement