basics · beginner · ~15 min
Walk the diagonal (i, i) of a flattened square matrix.
Implement long diag_sum(const int *m, int n) returning the sum of the main diagonal of an n x n row-major matrix.
long diag_sum(const int *m, int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.