TQC+ 程式語言 Python 3 _ 508 最大公因數

說明:
請撰寫一程式,讓使用者輸入兩個正整數x、y,並將x與y傳遞給名為compute()的函式,此函式回傳x和y的最大公因數。
範例輸入1:
12,8
範例輸出1:
4
範例輸入2:
4,6
範例輸出2:
2
程式碼:
def compute( m , n ):
    if n==0:
        return output(m)
    else:
        compute(n , m%n)

def output(m):
    print(m)
    
x, y = map(int, input().split(','))
compute(x,y)

沒有留言:

張貼留言