No problem with the stack.
But a verify big problem with the implementation.
Add a global variable that gets incremented for each call to your
Fibonacci function (increment the variable first in your function, before
you start looking at the N variable).
Run your program with N = 1, 10, 20, 30, 40 and emit the call counter.
Notice why your program takes a lot of time?
The Fibonacci series is trivial to evaluate in a loop, and a good example
of a recursively defined function that should _not_ be implemented with
recursion! Another such function is the factorial (n!).
/pwm
On Sun, 29 Jun 2008, Vijay Durga Reddy Annapureddy wrote:
> I have written the code for fibonacci numbers in c++.
> There is no error in that recursive logic.
> But to print the series from 45onwards it is taking a lot of time.
> I think it is due to stack,So please help me regarding this.
> Thank you.
>
|