Dcoder icon

Symmetric Matrix @ Dcoder

By Lochard | As a newbie programmer | 1 Aug 2023


Problem: Given a matrix of dimensions N x N.

Print "YES"(without quotes) if it is a symmetric matrix, else print "NO"(without quotes).

 

Input: First line contains N.

Each of following N lines contains N integers each, denoting the matrix.

 

Output: Print the required answer.

Constraints: 1 <= N <= 100

1 <= matrix_element <= 100

Sample Input: 3

1 0 0

0 2 1

0 1 1

 

Sample Output: 

YES

n = int( input() )
matrix = []
for i in range( n ):
    matrix.append( input().split() )
  
for i in range( 1, n - 1 ):
    for j in range( i, n ):
        if matrix[i][j] != matrix[j][i]:
            print( "NO" )
            break
    else:
        continue
    
    break
else:
    print( "YES" )

How do you rate this article?

1


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.