Advertisement
tegusta

Fibonacci (recursion method)

May 13th, 2012
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. /*
  2. Studente : Scia Massimiliano
  3. Classe : 3IC
  4. Data : 13/05/12 13:49
  5. Nome del file : ricorsione fibonacci
  6. */
  7.  
  8. #include <iostream>
  9. #include <cmath>
  10. #include <ctime>
  11. #include <cstdlib>
  12. #include <cctype>
  13. #include <windows.h>
  14. #include <fstream>
  15. #include <time.h>
  16. #include <stdio.h>
  17. #define N 100
  18.  
  19. using namespace std;
  20.  
  21. void end(void){
  22.     fflush(stdin);
  23.     cout<<"\n\nPremere Invio per continuare.";
  24.     getchar();
  25. }//end
  26.  
  27. int fibonacci(int n){
  28.     if(n<=0)
  29.         return 0;
  30.     if(n==1)
  31.         return 1;
  32.     if(n==2)
  33.         return 1;
  34.     return fibonacci(n-1) + fibonacci(n-2);
  35. }//fibonacci
  36.  
  37.  
  38. int main(){
  39.     int n;
  40.     cout<<"\nQuale numero della serie di Fibonacci vuoi sapere?\n- ";
  41.     cin>>n;
  42.     int k=fibonacci(n);
  43.     cout<<"\nIl "<<n<<"' numero della serie e`: "<<k<<".";
  44.     end();
  45.     return 0;
  46. }//main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement