lcm Algorithm

In arithmetical and number theory, the least common multiple, lowest common multiple, or smallest common multiple of two integers a and b, normally denoted by LCM(a, b), is the smallest positive integer that is divisible by both a and b. Since division of integers by zero is undefined, this definition has meaning only if a and b are both different from zero.
# LCM (Least Common Multiple) of two numbers is the smallest number which can be divided by both numbers.

p "Least Common Multiple"

p "Enter first number"
value_one = gets.chomp.to_i

p "Enter second number"
value_two = gets.chomp.to_i

def gcd(first, second)
  if second != 0
    gcd(second, first%second)
  else
    first
  end
end

def lcm(first, second)
  (first * second)/gcd(first, second)
end

p "Least Common Multiple is: #{lcm(value_one, value_two)}"

LANGUAGE:

DARK MODE: