QP School

Full Version: Least common multiple in Ruby
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
To get the least common multiple of 2 numbers we can use the lcm function.
In this example we want to know the least common multiple of 36 and 60.


Quote:num1 = 36
num2 = 60
lcm = num1.lcm(num2)

puts lcm


This will print 180 on the screen.