Page 428 - Computer Science Class 11 With Functions
P. 428
x = y
y = z
print(z, end=' ')
num = int(input("Enter a number: "))
print("The fibonacci series is: ")
fibonacci(num)
Program 10
Write a Python program that accepts two numbers from the user and displays their greater common divisor (GCD)
and least common multiple (LCM).
Ans. def GCD(num1,num2):
'''
Objective : To calculate the GCD of 2 numbers
Input Parameters : num1,num2 - numeric value
Return Value : gcd - numeric value
'''
gcd = 1
for i in range(1,num1+1):
if num1 % i == 0 and num2 % i == 0:
gcd = i
return gcd
def LCM(num1,num2,gcd):
'''
Objective : To calculate the LCM of 2 numbers
Input Parameter : num1,num2,gcd - numeric value
Return Value : gcd - numeric value
'''
lcm = num1 * num2 / gcd
return lcm
num1 = int(input("Enter first number : "))
num2 = int(input("Enter second number : "))
gcd = GCD(num1,num2)
print("GCD of ", num1, "and", num2, "is : ", gcd)
lcm = LCM(num1,num2,gcd)
print("LCM of ", num1, "and", num2, "is : ", lcm)
426 Touchpad Computer Science-XI

