Fibonacci Series
EasyNumbers & Math
The problem
Print the first n numbers of the Fibonacci series, where each number is the sum of the previous two.
Sample input
8
Sample output
0 1 1 2 3 5 8 13Show the solution · 8 languages
fun main() {
val n = 8
var a = 0
var b = 1
val out = mutableListOf<Int>()
repeat(n) {
out.add(a)
val next = a + b
a = b
b = next
}
println(out.joinToString(" "))
}