SHARE
TWEET

Kerrick

a guest Feb 15th, 2009 928 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  #include <iostream>
  2.  
  3.  int numofcalls;
  4.  
  5.  int Fibonacci(int nNumber)
  6.  {  
  7.          numofcalls++;
  8.      if (nNumber == 0)  
  9.          return 0;  
  10.      if (nNumber == 1)  
  11.          return 1;  
  12.      return Fibonacci(nNumber-1) + Fibonacci(nNumber-2);  
  13.  }  
  14.    
  15.  // And a main program to display the first 13 Fibonacci numbers  
  16.  int main(void)  
  17.  {  
  18.      using namespace std;  
  19.          int num;
  20.      for (int iii=0; iii < 13; iii++) {
  21.                  numofcalls = 0;
  22.                  num = Fibonacci(iii);
  23.          cout << "The " << iii << "th Fibonacci number is " << num << "; it took " << numofcalls
  24.                  << " calls to calculate it." << endl;
  25.          }
  26.    
  27.      return 0;  
  28.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top