Greatest common divisor: Difference between revisions

(Added Rust example)
Line 2,081:
=={{header|Scala}}==
<lang scala>def gcd(a: Int, b: Int): Int = if (b == 0) a.abs else gcd(b, a % b)</lang>
 
Using pattern matching
 
<lang scala>@tailrec
def gcd(a: Int, b: Int): Int = {
b match {
case 0 => a
case _ => gcd(b, (a % b))
}
}
 
=={{header|Scheme}}==
Anonymous user