Compute the classic Fibonacci running times quantitatively via the third variable
//Util.h static unsigned long long factorialLoops; long double Fibonacci35(int len); //Util.cpp unsigned long long Util::factorialLoops=0; long double Util::Fibonacci35(int i) { Util::factorialLoops++; if(i==0 || i==1) { return 1; } else { return Fibonacci35(i-1)+Fibonacci35(i-2); } } //main.cpp void recursion16(int i) { Util ul; long double fib = 0; for (int x = 0; x < i; x++) { fib = ul.Fibonacci35(x); cout <<fixed<< "Fib of " << x << " is " << fib <<",fibonacci loops is "<<Util::factorialLoops<<endl; } cout<<endl<<"The recursion loops is "<<Util::factorialLoops<<endl; } int main(int args, char **argv) { recursion16(atoi(argv[1])); return 0; }
Compile and run as below command which will cost more time definitely
./h1 100
The following snapshot can demonstrate everything
When run the 54 it call the classic Fibonacci method more than 730 billion times.