OlsonLiu
6/2/2019 - 8:51 AM

For loop Fibonacci

by Kotlin

import java.math.BigInteger

fun fibonacci(num: Int): BigInteger {
  var cnt = 0
  var first : BigInteger = BigInteger.ZERO
  var second : BigInteger = BigInteger.ONE
  var theSum : BigInteger = BigInteger.ZERO
  while (cnt <= num){
    theSum = first.add(second)
    first = second
    second = theSum
    cnt++
  }
  return theSum
}

fun main(args: Array<String>) {
  println(fibonacci(8180))
}