Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "math.h"
- #include <iomanip>
- using namespace std;
- int call_count = 0;
- int fib(int n)
- {
- call_count+=1;
- if(n == 1 || n == 2)
- return 1;
- if (n > 2)
- return fib(n-1) + fib(n-2);
- return n;
- }
- int main()
- {
- int num;
- cout<<"\nenter the number of integers to be printed in the fibonacci series\n";
- cin>>num;
- cout<<"\nfibonacci series for first "<<num<<" numbers is\n";
- cout<<"\n\nSerial Number\t"<<"FIBO_NUMBER\t"<<" NO_OF_CALLS MADE\n\n";
- for(int i=1;i<=num;i++)
- {
- call_count = 0;
- cout<<endl<<i<<"th number\t "<<fib(i)<<"\t\t";
- cout<<call_count-1<<" calls\n";
- }
- cout<<endl<<"\n the total number of recursive calls made were "<<call_count-1<<endl<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement