Restriction: No state is allowed in this question. Specifically, the keyword "var" is banned. (ie. You are expected to use a recursive solution)
Question: In a package named "functions" create an object named Numbers with a method named fib that: • Takes an Int as a parameter and returns the nth fibonacci number • Fibonacci numbers are equal to the sum of the previous two fibonacci numbers starting with 1 and 1 as the first two numbers in the sequence • Fibonacci numbers: 1, 1, 2, 3, 5, 8... • fib(1) == 1 • fib(2) == 1 • fib(3) == 2 • fib(4) == 3 • You method will not be tested with inputs < 1
Language: Scala
pls explain every steps thanks
Scala is a functional programming language, so I will write and explain the Fibonacci function in Scala.
The following code snippet 'fib' is the Fibonacci recursive function. It has to be called from the main function with an integer as an argument.
def fib( n : Int) : Int = n match {
case 0 | 1 => n
case _ => fib( n-1 ) + fib( n-2 )
}
The code is explained below :
The full code with the main function is attached below:

The main function calls the fib function with an integer value, let say 10, and it will return 55 as the 10th integer in Fibonacci series: 1 1 2 3 5 8 13 21 34 55.
Here is a small example of how the fib function works recursively with a small integer value, say 5.

I hope this will explain the code snippet of Fibonacci (recursion method), without using var.
Please leave a "Thumbs Up", it will be of great help. Thanks.
Happy Studying.
Restriction: No state is allowed in this question. Specifically, the keyword "var" is banned. (ie. You...