2D 配列の要素を次の行の要素で乗算するプログラムを作成しています。2 番目の行 (array[1][]) から始めて、最初に 2D 配列のすべての行を反復処理し、0 以外の配列値がある場所を見つけてから、その値を取り、それを配列の次の行で関数を実行するための再帰呼び出し。私の問題は、関数を実行し、1、2、および 3x3 配列をパラメーターとして渡すと、配列が配列 [1] [2] と配列 [2] [0] の両方に 2 を含む場合、0 が返されることです。 (slopeArray[current][i]) は 2 であり、これも 2 である必要がある基本ケースで乗算する必要があると考えました。すべてを手で書き出すと、次のようになりました。 4 を返す必要があります。
int total(int current, int totalCont, int array[3][3]){
//find the elements in the array that do not contain 0
for(int i=0; i<3; i++){
if(array[current][i] != 0){
//base case
if(current == totalCont){
return array[current][i];
}
//recursive case
else{
(array[current][i]) * (total(current+1, totalCont, array));
}
}
}
}