about | help | code help+videos | done | prefs |
The Fibonacci numbers are the numbers in the following integer sequence. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144... The first two values are 0 and 1. Each subsequent value is calculated as the sum of the prior two values. Write a function that return's the nth number in the sequence While this can be done recursively, a loop is actually very efficient. Assume n >= 0. Hint: Write the solution as if you were doing it on paper, starting with small numbers and working your way up. Your loop needs to keep track of the two prior values in order to calculate the current. iterativeFib(0) → 0 iterativeFib(19) → 4181 iterativeFib(20) → 6765 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Copyright Nick Parlante 2017 - privacy