IT's 우

파이썬 자료구조와 알고리즘_최대공약수 본문

알고리즘/파이썬 알고리즘

파이썬 자료구조와 알고리즘_최대공약수

디우 2021. 3. 13. 02:10
728x90

- 두 정수의 최대공약수(greatest common divisor, GCD)를 계산

 

# finding_gcd

def finding_gcd(a,b):
    while(b != 0):
       result = b
       a, b= b, a % b
return result

 

def test_finding_gcd():
    number1 = 21
    number2 = 12
    assert(finding_gcd(number1, number2) == 3)
    print("테스트 통과!")

if __name__ == "__main__":
test_finding_gcd()

 

 

 

 

출처: 파이썬 자료구조와 알고리즘, 미아 스타인 지음 최길우 옮김

728x90
반응형