Showing posts with label Least Common Denominator in JavaScript. Show all posts
Showing posts with label Least Common Denominator in JavaScript. Show all posts

Saturday, November 21, 2015

Least Common Denominator in JavaScript

A simple least common denominator in JavaScript that will ask a number and determine the least common denominator  values of the number.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
 <head>
   <title> Least Common Denominator </title>
  </head>
  <style>
  h3 {
     font-family:arial;
 </style>
 <body> 
 <h3> Least Common Denominator </h3>
 <script>

 function LCM(A)  
{   
    var n = A.length, a = Math.abs(A[0]);
    for (var i = 1; i < n; i++)
     { var b = Math.abs(A[i]), c = a;
       while (a && b){ a > b ? a %= b : b %= a; } 
       a = Math.abs(c*A[i])/(a+b);
     }
    return a;
}

 val_1 = Number(prompt("Enter First Number  : "));
 val_2 = Number(prompt("Enter Second Number : "));


document.write("<font face='arial' face='14'> <b>");
document.write("The Least Common Denomination of " + val_1 + " and " + val_2 
  + " is " + LCM([val_1, val_2])+". <b></font>"); 
</script>
</body>
</html>