GCD/LCM of 2 numbers

4.62K viewsMathematicsProgramming
0

How do I find GCD/LCM of 2 numbers ?

Changed status to publish
0

Below is the algorithm:-

console.log("GCD of 35 and 75 ", gcd(35, 75));
console.log("LCM of 35 and 75 ", (35*75)/gcd(35,75));
/* function to calculate GCD/HCF of 2 numbers */
 function gcd(i, j) {
 var r = -1;
  if (i < j) {
  var temp;
  temp = i;
  i = j;
  j = temp;
 }
  while (r) {
  r = i - parseInt(i / j) * j;
  i = j;
  j = r;
 }
  return i;
}

Edited answer
You are viewing 1 out of 1 answers, click here to view all answers.
Write your answer.

Categories