Ask coding questions

← Back to all posts
LCM program (wrong output)
h
SaunakNandi (1)

Plz help me to get the output , i dont know while doing recursion the value get passed return wrong value , plz check the program , its a LCM on python

Answered by TheForArkLD (770) [earned 5 cycles]
View Answer
Comments
hotnewtop
TheForArkLD (770)
  1. Use Euclidean Algorithm ( G = GCD(A, B), A ≧ B )
  2. LCM(A, B) = A * B / G
TheForArkLD (770)

@SaunakNandi oh no you solved problem by 9 months

PattanAhmed (1404)

@SaunakNandi Hi,
You need to change the code like this if you want a simple LCM program:-

a=int(input("Enter the first number: "))
b=int(input("Enter the second number: "))
if(a>b):
    min1=a
else:
    min1=b
while(1):
    if(min1%a==0 and min1%b==0):
        print("LCM is:",min1)
        break
    min1=min1+1

> Please mark my answer if this helps

dillonjoshua68 (73)

@SaunakNandi here @TheForArkLD

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

print("LCM is",lcm(x,y))
    
user_input = float(input(“Enter a number: “) # they can enter decimal numbers because of float
user_input_2 = float(input(“Enter a number: “) # same for this

# this is the end of the program, but you can do error handling if you want to...

if user_input.isdigit():
     pass
else:
     print(“Error!”)

if user_input_2.isdigit():
     pass
else:
     print(“Error!”)
TheForArkLD (770)

@dillonjoshua68 which is answer, yours or mine? lol

Coder100 (18089)

he's asking for a recursion solution here!
This is not recursion! @dillonjoshua68

dillonjoshua68 (73)

Sry idk a recursion solution for this @Coder100

this is the simplest I could do