100% Guaranteed Results


PCS – Write a method to calculate the Fibonacci sequence Solved
$ 20.99
Category:

Description

5/5 – (1 vote)

Write a version using iteration (a for-loop) and another version using recursion Use the code we wrote to calculate the factorial for inspiration What is the Fibonacci sequence?
https://en.wikipedia.org/wiki/Fibonacci_number

The Fibonacci sequence is a sequence in which each number is the sum of the two preceding ones. The sequence commonly starts from 0 and 1, (although some authors omit the initial terms and start the sequence from 1 and 1 or from 1 and 2). Starting from 0 and 1, the next few values in the sequence are:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …

0+1 = 1
1+1 = 2
1+2 = 3
2+3 = 5
3+5 = 8
Etc. etc.

So, the method you write should take an index and should return the correct number in the sequence.
For example, if you pass the method a 9 the method should return 34
DO NOT hardcode the sequence, the method needs to calculate what the correct number is. It needs to figure it out based on the 2 numbers before this index, adding them together and getting the answer.

Reviews

There are no reviews yet.

Be the first to review “PCS – Write a method to calculate the Fibonacci sequence Solved”

Your email address will not be published. Required fields are marked *

Related products