Способ аналогичен массиву 1D, пример:
#include <stdio.h>
#define ROWS 3
#define COLUMNS 4
/* compute the sum of arr[row][0] .. arr[row][COLUMNS - 1] */
int sumRow(int (*arr)[COLUMNS], int row, int col)
{
return (col == COLUMNS)
? 0
: sumRow(arr, row, col + 1) + arr[row][col];
}
/* compute the sum of arr[0][col] .. arr[nRow][col] */
int sumCol(int (*arr)[COLUMNS], int row, int nRow, int col)
{
return (row == nRow)
? 0
: sumCol(arr, row + 1, nRow, col) + arr[row][col];
}
int main()
{
int arr[ROWS][COLUMNS];
for (int r = 0; r != ROWS; ++r) {
for (int c = 0; c != COLUMNS; ++c) {
arr[r][c] = 10*r + c;
printf("%3d", arr[r][c]);
}
}
printf("sum[2][*] = %d\n", sumRow(arr, 2, 0));
printf("sum[*][1] = %d\n", sumCol(arr, 0, ROWS, 1));
}
Компиляция и выполнение:
pi@raspberrypi:/tmp $ gcc -pedantic -Wextra rc.c
pi@raspberrypi:/tmp $ ./a.out
0 1 2 3
10 11 12 13
20 21 22 23
sum[2][*] = 86
sum[*][1] = 33
20 + 21 + 22 + 23 = 86
1 + 11 + 21 = 33
Конечно, здесь рекурсия может быть легко удалена, но это не предмет, и рекурсия была запрошена