Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is cultural tourism and why is it growing?

Answered: 1 week ago