B.Sc Computer Science with Data Analytics
Python Programming - Lab
Core Lab 5
Bharathiar University
Program 5 - Write recursive functions for GCD of two integers.
SOURCE CODE
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
# Example usage
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
result = gcd(num1, num2)
print("GCD of", num1, "and", num2, "is:", result)
OUTPUT:
Enter the first integer: 12
Enter the second integer: 24
GCD of 12 and 24 is: 12
No comments:
Post a Comment