int sum = 0; for (int i = 0; i < m; ++i) { int temp = 1; for (int j = 0; j < i; ++j) { temp *= a[i * m + j]; } sum += temp; }