#include <iostream> #include <time.h> using namespace std; long Fib(int n, long& count); long NonFib(int n, long& count); const int US_TO_SEC = 1000000; int main() { int i = 1; int n = 1; clock_t start, stop, time; long count = 0; long fibTemp; long nonFibTemp; fibTemp = Fib(n, count); nonFibTemp = NonFib(n, count); start = clock(); Fib(10, count ); stop = clock(); time = stop-start; cout << "Recursive version" << endl; for(i=1;i<=20;i++) { cout << "Fib(" << i << ") = " << fibTemp << " calls "; cout << count << endl; } cout << "That took " << time << " microseconds or " << time/US_TO_SEC << " seconds." << endl; cout << endl << "Non-recursive version" << endl; for(i=1;i<=20;i++) { cout << "Fib(" << i << ") = " << nonFibTemp << " loops "; cout << count << endl; } cout << "That took " << time << " microseconds or " << time/US_TO_SEC << " seconds." << endl; return 0; } //recursive fibonacci function long Fib(int n, long& count) { long returnValue; count++; // cout << n << " " << count << endl << endl; if (n == 1 or n == 2) { returnValue = 1; } else { returnValue = (Fib(n-1, count) + Fib(n-2, count)); } return returnValue; } //non recursive fibonacci function long NonFib(int n, long& count) { long prev = -1; long result = 1; long sum; int i; count++; for(i = 0;i <= n;++ i) { sum = (result + prev); prev = result; result = sum; } return result; }

i've tried all that i can and i'm not sure what else to do Recursive version Fib(1) = 1 calls 111 Fib(2) = 1 calls 111 Fib(3) = 1 calls 111 Fib(4) = 1 calls 111 Fib(5) = 1 calls 111 Fib(6) = 1 calls 111 Fib(7) = 1 calls 111 Fib(8) = 1 calls 111 Fib(9) = 1 calls 111 Fib(10) = 1 calls 111 Fib(11) = 1 calls 111 Fib(12) = 1 calls 111 Fib(13) = 1 calls 111 Fib(14) = 1 calls 111 Fib(15) = 1 calls 111 Fib(16) = 1 calls 111 Fib(17) = 1 calls 111 Fib(18) = 1 calls 111 Fib(19) = 1 calls 111 Fib(20) = 1 calls 111 That took 0 microseconds or 0 seconds. Non-recursive version Fib(1) = 1 loops 111 Fib(2) = 1 loops 111 Fib(3) = 1 loops 111 Fib(4) = 1 loops 111 Fib(5) = 1 loops 111 Fib(6) = 1 loops 111 Fib(7) = 1 loops 111 Fib(8) = 1 loops 111 Fib(9) = 1 loops 111 Fib(10) = 1 loops 111 Fib(11) = 1 loops 111 Fib(12) = 1 loops 111 Fib(13) = 1 loops 111 Fib(14) = 1 loops 111 Fib(15) = 1 loops 111 Fib(16) = 1 loops 111 Fib(17) = 1 loops 111 Fib(18) = 1 loops 111 Fib(19) = 1 loops 111 Fib(20) = 1 loops 111 That took 0 microseconds or 0 seconds.