Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

gcd using js

function gcd(a, b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

console.log(gcd(24, 30)) // 6
console.log(24 / 6, 30 / 6) // 4 5
//////////////////
//				//
//  4 * 6 = 24  //
//  5 * 6 = 30  //
//              //
//////////////////
 
PREVIOUS NEXT
Tagged: #gcd #js
ADD COMMENT
Topic
Name
2+3 =