Advertisement
informaticage

Ricorsione con Fibonacci

Sep 18th, 2014
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int fibonacci(int n) {
  7.     if(n <=1)
  8.         return 1;
  9.     else
  10.         return fibonacci(n - 1) + fibonacci(n - 2);
  11. }
  12.  
  13. int main(int argc, char *argv[])
  14. {  
  15.     int num;
  16.     cout << "inserire N: " << endl;
  17.     cin >> num;
  18.     cout << "fibonacci: " << fibonacci(num) << endl;
  19.     cout << "Press the enter key to continue ...";
  20.     cin.get();
  21.     cin.get();
  22.     return EXIT_SUCCESS;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement