M.Sc Python Programming Assignment 21

M.Sc Python Programming Assignments

Assignment 21

Question:

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

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: "))

gcd_result = gcd(num1, num2)

print("Greatest Common Divisor (GCD):", gcd_result)

				
			

Output:

				
					Enter the first integer: 55
Enter the second integer: 75
Greatest Common Divisor (GCD): 5

				
			
Tech Amplifier Final Logo