Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include "math.h"
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int call_count = 0;
  8.  
  9. int fib(int n)
  10. {
  11. call_count+=1;
  12. if(n == 1 || n == 2)
  13.  
  14. return 1;
  15.  
  16. if (n > 2)
  17. return fib(n-1) + fib(n-2);
  18.  
  19. return n;
  20. }
  21.  
  22. int main()
  23. {
  24. int num;
  25. cout<<"\nenter the number of integers to be printed in the fibonacci series\n";
  26. cin>>num;
  27. cout<<"\nfibonacci series for first "<<num<<" numbers is\n";
  28. cout<<"\n\nSerial Number\t"<<"FIBO_NUMBER\t"<<" NO_OF_CALLS MADE\n\n";
  29. for(int i=1;i<=num;i++)
  30. {
  31. call_count = 0;
  32. cout<<endl<<i<<"th number\t "<<fib(i)<<"\t\t";
  33. cout<<call_count-1<<" calls\n";
  34. }
  35. cout<<endl<<"\n the total number of recursive calls made were "<<call_count-1<<endl<<endl;
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement