Diagonals and Symmetry

Lab C Intermediate 20 points

Read an n×n matrix. Print the main-diagonal sum, the anti-diagonal sum, and symmetric or not symmetric.

Input

n, then n rows.

Output

Three lines.

Example

Input

3
1 2 3
2 5 6
3 6 9

Output

15
11
symmetric
Sample input available Sample output available
Editor
C

Hints

Symmetric means m[i][j] == m[j][i] for all i, j.

Solution explanation

The anti-diagonal is where i + j == n - 1.

Show solution
#include <stdio.h>

int main() {
    int n, m[10][10], d1 = 0, d2 = 0, sym = 1;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            scanf("%d", &m[i][j]);
    for (int i = 0; i < n; i++) {
        d1 += m[i][i];
        d2 += m[i][n - 1 - i];
        for (int j = 0; j < n; j++) {
            if (m[i][j] != m[j][i]) sym = 0;
        }
    }
    printf("%d\n%d\n%s\n", d1, d2, sym ? "symmetric" : "not symmetric");
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD