主对角线一下的元素都为0
如:3 2 1
0 1 1
0 0 4
输入n阶方阵,并输入n行n列的数
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>//上三角形矩阵判定int main()
{int n = 0;scanf("%d", &n);//输入矩阵行列int arr[10][10];int i = 0;int j = 0;int flag = 1;for (i = 0;i < n;i++){for (j = 0;j < n;j++){scanf("%d", &arr[i][j]);}}for (i = 0;i < n;i++){for (j = 0;j < i;j++){if (arr[i][j] != 0){flag = 0;goto end;}}}
end:if (flag == 1)printf("YES\n");elseprintf("NO\n");return 0;
}