Question 3: Please give a) and b) answer. Thanks. The Fibonacci sequence is the
ID: 3885434 • Letter: Q
Question
Question 3: Please give a) and b) answer. Thanks.
The Fibonacci sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2) And the 5 is (2+3), and so on! Write an algorithm which would be able to get two input numbers, n and P and process the following requirements: (a) If the first three Fibonacci numbers are given as 1, 1 and 2, then what is the n-th number? Find the number value. (b) If the first three Fibonacci numbers are given as x_1 = 1, x_2 = 1 and x_3 = 2, then what is the least value of n for which x_n > P? Find the n value.Explanation / Answer
a)
INPUT N
FIB[1] = 1
FIB[2] = 1
FIB[3] = 2
FOR i 4 TO N
FIB[I] = FIB[I-1] + FIB[I-2]
PRINT FIB[N]
b)INPUT P
FIB[1] = 1
FIB[2] = 1
FIB[3] = 2
N = 3
WHILE FIB[N]<=P
FIB[N] = FIB[N-1] + FIB[N-2]
N = N+1
PRINT N
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.