i can do a recursive function to compute the nth Fibonacci term as follows:
int rec (int i)
{
if(i == 1 || i == 2)
return i;
else return rec(i-1)+rec(i-2);
}
But i want to use the golden number which is 1.618 to compute the Fibonacci; but my attempt fails, i get wrong numbers:
int rec (int i)
{
if(i == 1 || i == 2)
return i;
else return 1.618*rec(i-1);
}
How can i get it to work?
The golden ratio is an irrational number, so you shouldn't necessarily expect to be able to plug an approximation of it into a formula to get an exact result.
If you want to know how to calculate the n
th fibonacci number quickly, here is a page that lists a variety of methods in decreasing order of runtime (but increasing in order of implementation difficulty): https://www.nayuki.io/page/fast-fibonacci-algorithms
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With