fork download
  1. fun fib(n: Int): Int {
  2. var f1 = 1
  3. var f2 = 1
  4.  
  5. for (i in 3 until n + 1) {
  6. val f3 = f1 + f2
  7. f1 = f2
  8. f2 = f3
  9. }
  10.  
  11. return f2
  12. }
  13.  
  14. fun main() {
  15. val n = 10
  16.  
  17. val result = fib(n)
  18.  
  19. println("fib($n) = $result")
  20. }
Success #stdin #stdout 0.08s 40596KB
stdin
Standard input is empty
stdout
fib(10) = 55