GCD/LCM of 2 numbers

5.58K 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;
}

Changed status to publish
Write your answer.

Categories