Finding the Least Common Multiple

Learn to find the least common multiple for two numbers in Ruby.

Problem

Write a program that asks the user to enter two non-negative integers and finds their least common multiple (LCM).

The least common multiple (LCM) is the smallest non-zero number, which is a multiple of two or more numbers. For example, 1212 is the least common multiple of 66 and 44, as 12=6×212 = 6 \times 2 and 12=3×412 = 3 \times 4. Note that 2424 is also a common multiple of 44 and 66 but it is not the lowest.

Get hands-on with 1400+ tech skills courses.