What is the LCM of two numbers?

The lowest common multiple (LCM) is the lowest multiple shared by two or more numbers. For example, for the numbers 2 and 5, the lowest common multiple is 10 – the number both numbers can multiply into without a remainder.

Write a program that outputs the LCM of two numbers input.

Use this boilerplate code as a starting point:

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

- Takes two parameters: number1 and number2.
- Starts a counter at the highest of the two numbers.
- Counts up until the counter is divisible by both numbers with no remainder.
- Returns the counter.

- The user can input two numbers.
- The result is calculated by calling the subprogram lcm.
- The result is output in the format: “The LCM of {number1} and {number2} is {result}”.

Enter the first number: 2

Enter the second number: 5

The lcd of 2 and 5 is 10.

Enter the first number: 6

Enter the second number: 4

The LCM of 6 and 4 is 12.

Enter the first number: 7

Enter the second number: 40

The LCM of 7 and 40 is 280.

Enter the first number: 2

Enter the second number: 10

The LCM of 2 and 10 is 10.

Use these resources as a reference to help you meet the success criteria.

Run the unit tests below to check that your program has met the success criteria.

Enter the first number: 2

Enter the second number: 4

The LCM of 2 and 4 is 4.

Enter the first number: 8

Enter the second number: 8

The LCM of 8 and 8 is 8.

Enter the first number: 6

Enter the second number: 4

The LCM of 6 and 4 is 12.

Enter the first number: 8

Enter the second number: 10

The LCM of 8 and 10 is 40.

Enter the first number: 16

Enter the second number: 72

The LCM of 16 and 72 is 144.

Check that you have:

- Used comments within the code to describe the purpose of subprograms, conditions and iterations.
- Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.