Calculators Effects >>> Least Common Multiple and Greatest Common Divisor.
 
Script Categories













Calculators >>> Least Common Multiple and Greatest Common Divisor.

Calculate the Least Common Multiple and Greatest Common Divisor of two numbers using this short script.

First Value
Second Value


Least Common Multiple
Greatest Common Divisor

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function getGCD() {
var w, x, y;
x = document.lcm_gcd.a.value;
y = document.lcm_gcd.b.value;
while (y != 0) {
w = x % y;
x = y;
y = w;
}
return x;
}
function getLCM() {
var gcd = getGCD();
var lcm = (document.lcm_gcd.a.value * document.lcm_gcd.b.value) / gcd;
document.lcm_gcd.lcmA.value = lcm;
document.lcm_gcd.gcdA.value = gcd;
}
//  End -->
</script>
<form name=lcm_gcd>
<table border=0>
<tr>
<td
width=200>
First Value
<br>
<input type=text name=a>
</td>
<td
width=200>
Second Value
<br>
<input type=text name=b>
</td>
</tr>
<tr>
<td
colspan=2 align=center>
<br>
<input type=button value=Solve onClick="getLCM()">
<br>
</td>
</tr>
<tr>
<td>
Least Common Multiple
<br>
<input type=text name=lcmA>
</td>
<td>
Greatest Common Divisor
<br>
<input type=text name=gcdA>
</td>
</tr>
</table>
</form>

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.



Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).




©