|
From: Mansoor N. <man...@sy...> - 2001-11-09 20:46:07
|
Can any one please show me how to increase the efficiency of this
recursive program?
THe program is supposed to output the fibonacci sequence up to a given
value.
I need it to output in the middle of the recursive function, but
a lot of garbage gets acumulated.
Any help would be appreciated.
Thanks
Mansoor
#include <iostream.h>
int fib(int z);
void main(void)
{
int c;
for (int abc=0;abc<10;abc++)
cout<<fib(abc)<<endl;
cin>>c;
}
int fib(int z)
{
if (z==-1)
return 1;
if (z==-2)
return 0;
else
return (fib(z-1)+fib(z-2));
}
|