JavaScript program to find the LCM of two numbers:

Created with Sketch.

JavaScript program to find the LCM of two numbers:

let firstNumber = parseInt(prompt("Enter the first number:"));
let secondNumber = parseInt(prompt("Enter the second number:"));

let gcd = 1;
let max = Math.max(firstNumber, secondNumber);
for (let i = 2; i <= max; i++) {
  if (firstNumber % i === 0 && secondNumber % i === 0) {
    gcd = i;
  }
}

let lcm = (firstNumber * secondNumber) / gcd;
console.log("The LCM of the numbers is: " + lcm);

Leave a Reply

Your email address will not be published. Required fields are marked *