JavaScript program to find the HCF or GCD of two numbers using the Euclidean algorithm:

Created with Sketch.

JavaScript program to find the HCF or GCD of two numbers using the Euclidean algorithm:

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

while (secondNumber !== 0) {
  let temp = secondNumber;
  secondNumber = firstNumber % secondNumber;
  firstNumber = temp;
}

console.log("The HCF or GCD of the numbers is: " + firstNumber);

Leave a Reply

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