Answered step by step
Verified Expert Solution
Question
1 Approved Answer
SML/NJ Modify the function below to print out the value of x, fibonacci(x-1) and fibonacci(x-2) in every iteration of the function call: fun fibonacci (x:int)
SML/NJ
Modify the function below to print out the value of x, fibonacci(x-1) and fibonacci(x-2) in every iteration of the function call:
fun fibonacci (x:int) =
if (x = 0 orelse x = 1)
then x
else fibonacci(x-1) + fibonacci(x-2)
The expression
fibonacci 5;
would produce the output:
x = 1
x = 0
x = 2 f(x-1) = 1 f(x-2) = 0
x = 1
x = 3 f(x-1) = 1 f(x-2) = 1
x = 1
x = 0
x = 2 f(x-1) = 1 f(x-2) = 0
x = 4 f(x-1) = 2 f(x-2) = 1
x = 1
x = 0
x = 2 f(x-1) = 1 f(x-2) = 0
x = 1
x = 3 f(x-1) = 1 f(x-2) = 1
x = 5 f(x-1) = 3 f(x-2) = 2
val it = 5 : int
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started