Write a kotlin program to print fibonacci series.

In mathematics, the Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers in the following integer sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144...

By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. Below example shows how to create fibonacci series. Kotlin program to print fibonacci series


fun main(args: Array<String>) {

    val febCount = 15
    val feb = IntArray(febCount)
    feb[0] = 0
    feb[1] = 1
    for (i in 2 until febCount) {
        feb[i] = feb[i - 1] + feb[i - 2]
    }

    for (i in 0 until febCount) {
        print(feb[i].toString() + " ")
    }
}


Output


0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 

 
Join My Facebook Group
Join Group
 

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions