Search code examples
matrixsymmetric

How to efficiently check that a matrix is symmetric with respect to the secondary diagonal


I know how to check for the main diagonal symmetry.

for (line=0;line<size;line++)
    for (column=0;column<size;column++)
        if (matrix[line][column]!=matrix[column][line])
            return false;
return true;

How do i replace the condition inside the if to check the symmetry with respect to the secondary diagonal?

Thanks!


Solution

  • I figured it out! The if becomes:

    if (matrix[line][column]!=matrix[size-column-1][size-line-1])
        return false;