The Fibonacci sequence: unsigned fibonacci(unsigned void fibonacci(unsigned f[], unsigned n); n, unsigned& recursions); The first function is to solve the problem recursively and return the Fibonacci value of n as the result. In addition, it shall store the number of recursive calls in the recursions parameter.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question
100%

I really need help please this problem is very confusing for me it is in C++

The Fibonacci sequence:
unsigned fibonacci (unsigned n, unsigned& recursions);
void fibonacci(unsigned f[], unsigned n);
The first function is to solve the problem recursively and return the Fibonacci value of n as the
result. In addition, it shall store the number of recursive calls in the recursions parameter.
For example, assume recursions is an unsigned int variable in main() and is set to 0 before
each of call to the fibonacci function.
Calling fibonacci (0, recursions) should return 1 and store 0 in recursions since
there is no need for recursive call.
●
Calling fibonacci (2, recursions) should return 2 and store 2 in recursions since
this call would have trigger two recursive calls: fibonacci (0, recursions) and
fibonacci (1, recursions).
Calling fibonacci (3, recursions) should return 3 and store 4 in recursions since
this call would first trigger fibonacci (2, recursions) and fibonacci (1,
recursions). In addition, fibonacci (2, recursions) would trigger fibonacci (1,
recursions) and fibonacci (0, recursions).
The second function is to create the first n values of the Fibonacci sequence and store them in
the array parameter using an iterative approach. Do not use any nested loop. For example,
assume results is an array of unsigned int.
Calling fibonacci (results, 5) should store {1, 1, 2, 3, 5} in the first five elements of
results.
Calling fibonacci (results, 10) should store {1, 1, 2, 3, 5, 8, 13, 21, 34, 55} in the first
ten elements of results.
Transcribed Image Text:The Fibonacci sequence: unsigned fibonacci (unsigned n, unsigned& recursions); void fibonacci(unsigned f[], unsigned n); The first function is to solve the problem recursively and return the Fibonacci value of n as the result. In addition, it shall store the number of recursive calls in the recursions parameter. For example, assume recursions is an unsigned int variable in main() and is set to 0 before each of call to the fibonacci function. Calling fibonacci (0, recursions) should return 1 and store 0 in recursions since there is no need for recursive call. ● Calling fibonacci (2, recursions) should return 2 and store 2 in recursions since this call would have trigger two recursive calls: fibonacci (0, recursions) and fibonacci (1, recursions). Calling fibonacci (3, recursions) should return 3 and store 4 in recursions since this call would first trigger fibonacci (2, recursions) and fibonacci (1, recursions). In addition, fibonacci (2, recursions) would trigger fibonacci (1, recursions) and fibonacci (0, recursions). The second function is to create the first n values of the Fibonacci sequence and store them in the array parameter using an iterative approach. Do not use any nested loop. For example, assume results is an array of unsigned int. Calling fibonacci (results, 5) should store {1, 1, 2, 3, 5} in the first five elements of results. Calling fibonacci (results, 10) should store {1, 1, 2, 3, 5, 8, 13, 21, 34, 55} in the first ten elements of results.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

What are the pros and cons of using either the first or second function listed?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning