#include /* int f(const int n) { if (n <= 1) return 1; const int a = f(n-1); const int b = f(n-2); return a + b; } // That version is incredibly slow. Why? */ // In this version, "accidentally" replace the == with = // what happens and why? int f(int n, int a, int b) { if (n == 0) return b; return f(n-1, a+b, a); } int f(int n) { return f(n, 1, 1); } /* int f(const int n) { int i = 0, a = 1, b = 0; while (i < n) { const int temp = a + b; b = a; a = temp; i = i + 1; } return a; } // Do you really think that's any better? or easier to understand? // I don't */ void main() { int x = 1; while (true) { cout << x << ": " << f(x) << "\n"; x = x + 1; } }