## Printing Fibonacci series in Scala – Normal Recursion

Hey there! Welcome to ClearUrDoubt.com. In this post, we will look at a Scala program to print Fibonacci series using simple Recursion. Fibonacci Series: Finding n’th element: f(n) = f(n-1) + f(n-2)

1 2 3 4 5 6 7 8 9 10 11 12 |
package com.clearurdoubt object Fibonacci extends App { def fibonacci(n: Int): List[Int] = { def fibonacci(a: Int, b: Int): LazyList[Int] = a #:: fibonacci(b, a+b) fibonacci(0,1).take(n).toList } fibonacci(10) } |

Output: Happy learning. Please leave a reply Read more