arrays - Calculating Fibonacci Numbers in C++ code -
my question is: have matrix. need calculate corresponding fibonacci number each entry in matrix, , return values matrix. keep getting c2109 "subscript requires array or pointer type", , know it's coming from, , know means, don't know how
- fix
- make code work.
right now, doesn't anything. i'm not sure if i'm returning value fibonacci function, or calling correctly in main function. i've modified was. here's new code:
const int row1 = 3; const int col1row2 = 3; const int col2 = 3; int fibonacci (int [][col2]); void main() { int p[row1][col2], f [row1][col2]; int sum; input (a,b); cout<<"the fibonacci matrix is: "; cout<<fibonacci(p); ( int = 0; < row1; i++) { ( int j = 0; j < col2; j++) { sum = f[i][j]; f[i][j] = fibonacci(p); } } cout<<endl; } int fibonacci (int z[][col2]) { int fib [100] = {0 , 1}; int sum = 0; ( int m = 2; m < 100; m++) { sum = fib[m-1] + fib[m-2]; fib[m] = sum; } return sum; cout<<endl; }
any appreciated!
i think problem line:
f [i][j] = fib [ p [i][j] ];
is trying call fib
function incorrectly. have right idea here, call function in c++ need use regular parentheses rather square brackets. think line should like
f [i][j] = fib ( p [i][j] );
as follow-up, implementation of fib
seems might incorrect. in particular, you're taking in 2 parameters corresponding matrices, never use values directly. instead, you're constructing new local array of fibonacci numbers. want have function return appropriate fibonacci number generates.
hope helps, , best of luck on journey c++!
Comments
Post a Comment