Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Program to find LCM of 2 given numbers
- # method to calculate gcd of 2 numbers
- def gcd(num1,num2):
- if num1 == 1 or num2 == 1:
- return 1
- if abs(num1 - num2) == 1:
- return 1
- while num1 != num2:
- if num1>num2:
- num1 -= num2
- else:
- num2 -= num1
- return num1
- # method to calculate LCM of 2 numbers
- def LCM(num1, num2):
- gcd_num = gcd(num1, num2)
- lcm = (num1 * num2) / gcd_num
- return lcm
- # main function
- cont = True
- while cont:
- number1 = int(input("\nEnter the first number : "))
- number2 = int(input("Enter the second number : "))
- answer = LCM(number1, number2)
- print("The LCM of " + str(number1) + " and " + str(number2) + " is " + str(answer))
- n = int(input("Do you want to continue (1/0): "))
- if n == 0:
- cont = False
- print()
- '''
- Enter the first number : 14
- Enter the second number : 16
- The LCM of 14 and 16 is 112.0
- Do you want to continue (1/0): 1
- Enter the first number : 15
- Enter the second number : 25
- The LCM of 15 and 25 is 75.0
- Do you want to continue (1/0): 0
- '''
Add Comment
Please, Sign In to add comment