python 求两个数的最大公约数

给定两个整数a,b,求他们的最大公约数

def gcd(a,b):
    if a<b:
        a,b=b,a
    while(a%b != 0):
        c = a%b
        a=b
        b=c
    return b

a,b = map(int,input("请输入两个整数:").split()) #一次输入两个变量的方式
res = gcd(a,b)
print(res)

  

def gcd(a,b):
    if a%b == 0:
        return b
    else :
        gcd(b,a%b)

a,b = map(int,input("请输入两个整数:").split())
c = gcd(a,b)
print(c)

  

猜你喜欢

转载自www.cnblogs.com/jiaxinwei/p/11610652.html