GCD using Recursion
EasyRecursion
The problem
Find the greatest common divisor of two numbers using the recursive Euclidean algorithm.
Sample input
48, 18
Sample output
6Show the solution · 8 languages
fun gcd(a: Int, b: Int): Int {
if (b == 0) return a
return gcd(b, a % b)
}
fun main() {
println(gcd(48, 18))
}