16. //create first 2 series elements 17. series[0] = 0; 18. series[1] = 1; 19. 2
ID: 3627834 • Letter: 1
Question
16. //create first 2 series elements17. series[0] = 0;
18. series[1] = 1;
19.
20. //create the Fibonacci series and store it in an array
21. for(int i=2; i < limit; i++){
22. series[i] = series[i-1] + series[i-2];
23. }
0 1 1 2 3 5 8 etc
Can you please help me with line 22. Do I keep substituting i with int i in the for loop? (2,3,4 ---> limit). When I do that I don't get the correct outputs. I am missing the meaning in "create the Fibonacci series and store it in an array". I am doing this:
series [i] = 2-1 + 2-2
series [i] = series[1]
then:
series [i] = 3-1 + 3-2
series [i] = series[3]
then 4 and then 5 etc.
but this is wrong
Explanation / Answer
series [2] = series[2-1] + series[2-2] series [2] = series[1] + series[0] series [2] = 0 + 1 = 1 series [3] = series[3-1] + series[3-2] series [3] = series[2] + series[1] series [3] = 1 + 1 = 2 like that series goes..
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.