The upper triangular matrix refers to a matrix whose elements below the main diagonal are all 0; the main diagonal is the line from the upper left corner to the lower right corner of the matrix.
This question requires writing a program to determine whether a given square matrix is an upper triangular matrix.
Input format:
Input the first line to give a positive integer T, which is the number of the matrix to be tested. Next, the information of T matrices is given: the first row of each matrix information gives a positive integer n that does not exceed 10. Next n lines, each line gives n integers, separated by spaces.
Output format:
The judgment result of each matrix occupies one line. If the input matrix is the upper triangular matrix, output "YES", otherwise output "NO".
Input example:
2
3
1 2 3
0 4 5
0 0 6
2
1 0
-8 2
Output example:
YES
NO
title collection complete works portal
#include <stdio.h>
int main()
{
int t, n, count = 0, a[10][10];
scanf("%d", &t);
for (int k = 0; k < t; k++)
{
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
scanf("%d", &a[i][j]);
for (int i = 1; i < n; i++)
for (int j = i - 1; j >= 0; j--)
if (a[i][j] != 0)
count = 1;
if (count == 0)
printf("YES\n");
else
printf("NO\n");
count = 0;
}
return 0;
}