Competitive Programming Questions In Python |
In the article, we are going to write Python code to find the least common multiple between two integers.
If you are looking for a Python Tutorial then it's here
def lcm(x,y):
if x>y:
greater = x
else:
greater = y
while True:
if (greater % x ==0) and (greater % y ==0):
lcm = greater
break
greater += 1
return lcm
def main():
n1 = int(input('Enter first integer: '))
n2 = int(input('Enter second integer: '))
print('The Least common multiple is: ',lcm(n1,n2))
main()
he output of the above Python program is:
Enter first integer: 45
Enter second integer: 63
The Least common multiple is: 315
Enter first integer: 10
Enter second integer: 100
The Least common multiple is: 100
Comments
Post a Comment