by lokedhs · 10y ago · 0 comments
int Fibonacci(int n) { // calculate the n-th
int i; // Fibonacci number
int f; // by iteration
for i = 1 to n {
f = 2*f+i;
}
return f;
}With this sequence of numbers 1,1,2,3,5,8 it seems to be calculating
f=0 as 2 * 0+1=1 ; f=1 as 2 * 1+1=3 ; f=2 as 2 * 2+1=5 ; f=3 as 2 * 3+2=8 ;
then f=4 should be 2*5+3=13
I'm not sure how 2 is calculated unless i=0, but this is why I'm not even a novice.