View Code of Problem 51

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        int matrix[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> matrix[i][j];
            }
        }
        long long sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= i; j++) {
                sum += matrix[i][j];
            }
        }
        cout << sum << endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 51