Question: Question Ten Erlang Function Writing VI (3 points) You are teaching an Erlang class. You have asked your students to write a function to calculate

Question Ten Erlang Function Writing VI (3 points)

You are teaching an Erlang class. You have asked your students to write a function to calculate the Fibonacci numbers (write a function fib( N ) that returns the N-th Fibonacci number). A student comes to you to ask for help with their function. Here is what they have:

File name: tst.erl

-module (test).

-export ([fib/1]).

fib( 1 ) -> 1;

fib( 2 ) -> 1.

fib( N ) ->

fib( N 1 ) + N - 2.

Note: Make sure to only fix the error that is causing the problem the student mentions.

They say it will not compile. The first compile error says function fib/1 already defined. How can they fix this error?

The student has returned for more help. They have fixed the first error, but it still wont compile. Now it says module name 'test' does not match file name 'tst'. How can they fix this error?

The student has returned once again. They have fixed the second error, and now the file compiles. However, it is not giving the correct answers. The Fibonacci sequence that the students function returns is 1, 1, 2, 4, 7, 11, 16, What is wrong with the function, and how do you fix it?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!