Problem with fibonacci function. C++
问题 Should return the n place of the array. But instead of the value I'm only getting 0. int fibonacci(int n) { int f[100]; f[0] = 0; f[1] = 1; for (int i=2; i<n; i++) { f[i] = f[i-2] + f[i-1]; } return f[n]; } int main() { cout << fibonacci(3); return 0; } New CODE: New problem its returning one number further then it should. For example if 'n==7' its returning '13' not '8' like it should. int fibonacci(int n) { int f[100] = { 0, 1 }; for (int i=2; i<=n; i++) { f[i] = f[i-2] + f[i-1]; } return f