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