Full version: jsB@nk » Calculation » Math » Greatest Common Factor
URL: https://www.javascriptbank.com/greatest-common-factor.html
Find the Greatest Common Factor (GCF) of a group of two or three numbers.
Full version: jsB@nk » Calculation » Math » Greatest Common Factor
URL: https://www.javascriptbank.com/greatest-common-factor.html
<SCRIPT LANGUAGE="JavaScript">// Adam Hinz ([email protected]<!-- Beginfunction go(){var text1=eval(document.form1.text1.value)var text2=eval(document.form1.text2.value)var text3=eval(document.form1.text3.value)if (document.form1.text3.value==""){var text3=text1}var max1=Math.max(text1,text2)var max2=Math.max(max1,text3)for (i=-max2;i<=max2;i=i+1){var a=text1/ivar b=Math.floor(a)var c=a-bif (c==0){var first=1}else {var first=0}var a=text2/ivar b=Math.floor(a)var c=a-bif (c==0){var second=1}else {var second=0}var a=text3/ivar b=Math.floor(a)var c=a-bif (c==0){var third=1}else {var third=0}if ((first==1)&&(second==1)&&(third==1)){document.form1.answer.value=i}else{}}}// End --></script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<FORM NAME="form1">First Number:<INPUT TYPE="text" NAME="text1" SIZE="3">Second Number:<INPUT TYPE="text" NAME="text2" SIZE="3">Third Number:<INPUT TYPE="text" NAME="text3" SIZE="3"><BR><I>If you only want to do two numbers, leave the Third Box empty.</I><BR><BR><INPUT TYPE="button" VALUE="Find GCF" ONCLICK="go()"><INPUT TYPE="text" NAME="answer" SIZE="3"> is the Greatest Common Factor (GCF)<P></FORM><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->