Friday, October 20, 2023

Python Programming - Lab- Core Lab 5 - Bsc CS DA -Bharathiar University - Program 5 - Write recursive functions for GCD of two integers.

 

 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

Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...