Fibonacci Series

fun main() {
    println("Enter a number")//1
    var t2=1//2
    var t1=0//3
    var nextTerm=0//4
    val number = readLine()!!.toInt()//5
    if(number<=1)//6
    {
        println(number)//7
    }
    else
    {
        for(i in 1..number)//8
        {
          print("$t1,")//9
          nextTerm = t1+t2//10
            t1=t2//11
            t2=nextTerm//12
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *