I'm trying to solve a problem without using a loop but I don't find a way...
Let take this array for example: (assume there is randomize values)
1, 2, 3, 4, 5
2, 3, 4, 5, 6
3, 4, 5, 6, 7
4, 5, 6, 7, 8
5, 6, 7, 8, 9
By sending (row: 2, column: 1) I want to get the sum of:
1, 2
2, 3
3, 4
I write this recursion function to solve this problem:
static int Func(int[,] matrix, int row, int column)
{
if (row == -1 || column == -1)
return 0;
int result = 0;
for (int i = 0; i <= column; i++)
{
result += matrix[row, i];
}
return result + Func(matrix, row - 1, column);
}
That works, but I want replace the loop with extra call to function...