Lesson goal: Finding the Least Common Multiple (LCM)

Previous: A better GCD calculator | Home | Next: Finding common denominators using the LCM

If the past lessons on GCDs (here and here weren't enough for you, we now turn our attention to the LCM which stands for "least common multiple." The LCM is the smallest number that is a multiple of two numbers.

We introduce it here because the LCM can be calculated from the GCD using this formula:

$$LCM(a,b)=\frac{a\cdot b}{GCD(a,b)}$$

Now you try. Try completing the LCM function below using GCD function and the formula above.

Type your code here:


See your results here:

This program will not run! You have to fill in the return( ) statement in the function lcm(a,b) to compute the LCM of two numbers a and b, based on the formula involving the GCD above. Can you do it? Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.