/*
  For loops. see Nyhoff P129ff
 
  Fibonacci sequence is defined
  fib(n)=fib(n-1)+fib(n-2)
  https://en.wikipedia.org/wiki/Fibonacci_number
  
  0) What is the scope of n, fibprevprev, fibprev below.
  
  1) Change code to calculate the ratio of successive Fibonacci numbers fib(n)/fib(n-1)
     and show it converges to the golden ratio (1+sqrt(5))/2
  
  2) Change the order of of the two statements
         fibprevprev=fibprev;
         fibprev=fibnow;
     what happens and why?
 
  3) Increase N to 50, what happens and why?
  
  4) Write a function int Fibonacci(int n)  that returns the n'th Fibonacci number.
*/

#include <iostream>
using namespace std;

int main()
{
   int N=20;
   
   int fibprevprev=1, fibprev=1;
   for (int n=3; n<N ; n++)             // i loop variable                        
     {                                                           // fibprevprev is fib(n-2), fibprev is fib(n-1)
        int fibnow=fibprev + fibprevprev;                                        
        cout << "fib(" << n << ")=" << fibnow << endl;

        fibprevprev=fibprev;                                     // note order!
        fibprev=fibnow;
     }

   return 0;
}
