fork download
  1. fun gcd(num1: Int, num2: Int): Int {
  2. var a = num1
  3. var b = num2
  4.  
  5. while (b != 0) {
  6. val b2 = b
  7. b = a % b
  8. a = b2
  9. }
  10.  
  11. return a
  12. }
  13.  
  14. fun main() {
  15. val a = 32
  16. val b = 12
  17.  
  18. val result = gcd(a, b)
  19.  
  20. println("GCD($a, $b) = $result")
  21. }
Success #stdin #stdout 0.08s 36476KB
stdin
Standard input is empty
stdout
GCD(32, 12) = 4