Monday, June 29, 2020

Write a Recursive Python program to find the greatest common divisor (gcd) of two integers.

def Recurgcd(a, b): low = min(a, b) high = max(a, b) if low == 0: return high elif low == 1: return 1 else: return Recurgcd(low, high%low) print(Recurgcd(12,14))


Flowchart: Recursion: gcd of two integers.


Recurgcd(12,14)=return Recurgcd(low, high%low)

Recurgcd(12,14)=return Recurgcd(12,2))
Recurgcd(12,14)=return Recurgcd(return Recurgcd(2,0))
Recurgcd(12,14)=return Recurgcd(return 2)
Recurgcd(12,14)=return 2

No comments:

Post a Comment