a=int(input("Enter first number:"))
b=int(input("Enter second number:"))
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b,a%b)
GCD=gcd(a,b)
print("GCD is: ",GCD)
Output
Enter first number:85
Enter second number:20
GCD is: 5
def get_gcd(x, y):
while y:
x, y = y, x % y
return x
# Example usage
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("The GCD of", num1, "and", num2, "is", get_gcd(num1, num2))
import math
def get_gcd(x, y):
return math.gcd(x, y)
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("The GCD of", num1, "and", num2, "is", get_gcd(num1, num2))
Math module
def get_gcd(x, y):
while y:
x, y = y, x % y
return x # GCD of two numbers
# Function to compute LCM using the GCD
def get_lcm(x, y):
lcm = abs(x*y) // get_gcd(x, y)
return lcm
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("The LCM of", num1, "and", num2, "is", get_lcm(num1, num2))
Output
Enter first number: 20
Enter second number: 12
The LCM of 20 and 12 is 60
import math
# Function to compute LCM
def get_lcm(x, y):
return abs(x*y) // math.gcd(x, y)
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("The LCM of", num1, "and", num2, "is", get_lcm(num1, num2))
Learn more about recursive functions here. Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.