Find Gcd Flashcards
1
Q
How do you find the greatest common divisor of two integers? E.g. Gcd(60,24)
A
Function gcd(a,b) {
While(b!=0){
Remainder = a % b
A = b
B = remainder
}
Return a //Aka Euclid algorithm
}
—- recursive solution
function gcd(a,b) { if(b === 0) { return a; } return gcd(b, a % b); }