Pseudocode: An Iterative Algorithm for Fibonacci Numbers. 1 procedure iterative fibonacci(n: nonnegative integer) 2 if n = 0 then 3 return 0 4 else 5 x := 0 6 y := 1 7 for i := 1 to n - 1 8 z := x + y 9 x := y 10 y := z 11 return y 12 {output is the $n^{th}$ Fibonacci number}
Added by Christina J.
Close
Step 1
If n equals 0, return 0 immediately as specified in lines 2-3 of the pseudocode. Show more…
Show all steps
Your feedback will help us improve your experience
Kevin Corkran-Itagaki and 58 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Fibonacci Sequence The Fibonacci sequence is defined recursively by $a_{n+2}=a_{n}+a_{n+1},$ where $a_{1}=1$ and $a_{2}=1$ (a) Show that $\frac{1}{a_{n+1} a_{n+3}}=\frac{1}{a_{n+1} a_{n+2}}-\frac{1}{a_{n+2} a_{n+3}}$ (b) Show that $\sum_{n=0}^{\infty} \frac{1}{a_{n+1} a_{n+3}}=1$
Infinite Series
Series and Convergence
Fibonacci Sequence The Fibonacci sequence is defined recursively by $a_{n+2}=a_{n}+a_{n+1},$ where $a_{1}=1$ and $a_{2}=1$ $$ \begin{array}{l}{\text { (a) Show that } \frac{1}{a_{n+1} a_{n+3}}=\frac{1}{a_{n+1} a_{n+2}}-\frac{1}{a_{n+2} a_{n+3}}} \\ {\text { (b) Show that } \sum_{n=0}^{\infty} \frac{1}{a_{n+1} a_{n+3}}=1}\end{array} $$
Formula Using Fibonacci Numbers the sequence defined recursively by $$a_{n+1}=\frac{1}{1+a_{n}}$$ and let $a_{1}=1 .$ Find a formula for $a_{n}$ in terms of the Fibonacci numbers $F_{n} .$ Prove that the formula you found is valid for all natural numbers $n .$
Sequences and Series
Mathematical Induction
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD