Python Online Compiler
Example: GCD of Two Numbers in Python using Recursion
C
C++
C#
Java
Python
PHP
main.py
STDIN
Run
# GCD of Two Numbers in Python using Recursion # It's the recursive function to find the GCD def gcd(x, y): if x == y: return x else: if x > y: x = x - y else: y = y - x return gcd (x, y) # It's the driver code p, q = None, None # To store the two positive numbers print ("TWO POSITIVE INTEGER NUMBERS::") p = int (input ()) q = int (input ()) # It will print the final output print ("\nGCD =", gcd (p, q))
Output
Clear
ADVERTISEMENTS