Advertisement
comcmipi

GCD

Jun 24th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.24 KB | None | 0 0
  1. object Test {
  2.   def GCD(a: Int, b: Int): Int = {
  3.     a%b match {
  4.       case 0 => b
  5.       case _ => GCD(b, a%b)
  6.     } // match
  7.   } // def
  8.  
  9.   def main(args: Array[String]) {
  10.     println(GCD(16,28)) // should print 4
  11.   } // main
  12. } // object
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement