Начало
Калькуляторы
LCM and GCD
Вычислите Наименьшее количество Общего множителя и Самого большого Общего Делителя двух чисел, используя этот короткий скрипт.
First Value
Second Value
Least Common Multiple
Greatest Common Divisor
JavaScript Calculators: LCM and GCD
<!-- TWO STEPS TO INSTALL LCM AND GCD: 1. Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document --> <!-- STEP ONE: Paste this code into the HEAD of your HTML document --> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <! > <! > <!-- 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> </HEAD> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <BODY> <center> <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> </center> <!-- Script Size: 1.72 KB -->