#C7440. Diagonal Matrix Check
Diagonal Matrix Check
Diagonal Matrix Check
You are given an \(n \times n\) square matrix. A matrix is said to be a diagonal matrix if all elements outside the main diagonal are zero. More formally, a matrix \(A\) is diagonal if \(a_{ij} = 0\) for all \(i \neq j\).
Your task is to determine whether a given matrix is a diagonal matrix.
Input Format: The first line contains an integer \(n\), representing the dimensions of the matrix. Each of the following \(n\) lines contains \(n\) space-separated integers representing a row of the matrix.
Output Format: Print True
if the matrix is a diagonal matrix, otherwise print False
.
inputFormat
The first line of input contains a single integer \(n\), denoting the size of the square matrix. The next \(n\) lines each contain \(n\) space-separated integers representing a row of the matrix.
outputFormat
Output a single line: True
if the matrix is a diagonal matrix, otherwise False
.
3
1 0 0
0 5 0
0 0 9
True