/* Author : Mark Steeves, mlstvs Date : 17 October 1998 Task : Solution to Assignment 2, Problem 1 Description : This program will calculate all Fibonacci numbers below 5000 and display the ratio of every 4th and 5th number. The program also desplays the number of numbers generated. Filename : fib_rat.cpp */ #include #include int main() { int first, second, third; int fib_count; double golden; first = 1; second = 1; third = 0; golden = (sqrt(5.0) -1.0)/2.0; fib_count = 2; //This is initialized to 2 because two number are already //in the sequence. (that is 1, 1) //header to the output cout << "Here is the ratio of every 4th and 5th number,\nand its difference " << "from the \"Golden Ratio\"" << endl << endl; //loop to calculate Fibonacci numbers while(third <=5000) { third = first + second; fib_count ++; //Outputs the 5th sequence and the difference from the "golden ratio" if(fib_count % 5 == 0) { cout < " < 5000) fib_count --; cout<<"\nThere were " << fib_count << " numbers generated. " << endl; return(0); }