Kotlin Program to Display Fibonacci Series: In this program, you’ll learn to display the Fibonacci series in Kotlin using for and while loops. You’ll learn to display the series up to a specific term or a number.
The Fibonacci series is a series where the next term is the sum of the previous two terms. The first two terms of the Fibonacci sequence are 0 followed by 1.
Kotlin Program to Display Fibonacci Series
Source Code
fun main(args: Array<String>) {
val n = 10
var t1 = 0
var t2 = 1
print("First $n terms: ")
for (i in 1..n) {
print("$t1 + ")
val sum = t1 + t2
t1 = t2
t2 = sum
}
}
Output
Kotlin Program to Display Fibonacci Series