Greatest common factor (GCF) calculator. Is also known as greateset common divisor (GCD).
GCF calculator
GCF example
Find GCF for numbers 8 and 12:
The divisors of 8 are:
8 = 2×2×2
The divisors of 12 are:
12 = 2×2×3
So the common divisors of 8 and 12 are:
gcf = 2×2 = 4
So 8/12 fraction, can be reduced to 2/3:
8 / 12 = (8/4) / (12/4) = 2 / 3
gcf.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | <!doctype html> <html> <head> <meta charset="utf-8"> <title>code4examples.com</title> </head> <body> <form name="calcform" autocomplete="off"> <table class="calc2"> <tr> <td>First number:</td> <td><input type="number" step="any" name="a" class="intext" autofocus></td> </tr> <tr> <td>Second number:</td> <td><input type="number" step="any" name="b" class="intext"></td> </tr> <tr> <td> </td> <td><input type="button" value="Calculate" class="btn" onclick="gcfcalc()"> <input type="reset" value="✗" class="btn"></td> </tr> <tr> <td>Greatest common factor (gcf):</td> <td><input type="text" name="gcf" class="outtext" readonly></td> </tr> <tr> <td>Least common multiple (lcm):</td> <td><input type="text" name="lcm" class="outtext" readonly></td> </tr> </table> </form> <script> var gcd = function(a, b) { if ( ! b) { return a; } return gcd(b, a % b); }; function gcfcalc() { var a = document.calcform.a.value; var b = document.calcform.b.value; if( a!=Math.floor(a) || b!=Math.floor(b) ) { alert("Please enter integer numbers"); return; } if( a=='' || b=='' ) { alert("Please enter integer numbers"); return; } if( a==0 && b==0 ) { alert("Please enter at least one non zero integer"); return; } var g = gcd(a,b); if( g<0 ) g=-g; a = parseInt(a); b = parseInt(b); g = parseInt(g); var lcm = (a*b)/g; document.calcform.gcf.value = g; document.calcform.lcm.value = lcm; } </script> </body> </html> |