#include #include using namespace std; // first version, just print the first N things from the fibonacci sequence // use doubles because the numbers git big very quickly void fibseq1(int N) // number of numbers to be printed { double curr = 1; double prev = 1; while (N > 0) { const double next = prev + curr; cout << prev << "\n"; prev = curr; curr = next; N -= 1; } cout << "All done\n"; } // second version, look at the ratios between successive numbers void fibseq2(int N) { double curr = 1; double prev = 1; while (N > 0) { const double next = prev + curr; const double ratio = curr / prev; cout << prev << " " << ratio << "\n"; prev = curr; curr = next; N -= 1; } cout << "All done\n"; } // third experiment: the number 5 magically appears void fibseq(int N) { double curr = 1; double prev = 1; while (N > 0) { const double next = prev+curr; const double ratio = curr/prev; const double x = ratio * 2 - 1; const double xsq = x * x; cout << prev << " " << curr << " " << setprecision(17) << xsq << "\n"; prev = curr; curr = next; N -= 1; } cout << "All done\n"; } int main() { fibseq(1000); }