习题7-3 判断上三角矩阵

 1 #include<stdio.h>
 2 
 3 int main(void)
 4 {
 5     int t;
 6     scanf_s("%d", &t);
 7 
 8     for (int i = 0; i < t; i++)
 9     {
10         int n;
11         int a[10][10];
12 
13         scanf_s("%d", &n);
14         for (int j = 0; j < n; j++)
15         {
16             for (int k = 0; k < n; k++)
17             {
18                 scanf_s("%d", &a[j][k]);
19             }
20         }
21 
22         int flag = 0;        //标志位
23         for (int j = 0; j < n; j++)
24         {
25             for (int k = 0; k < j; k++)
26             {
27                 if (a[j][k] != 0)
28                 {
29                     flag = 1;
30                     break;
31                 }
32             }
33         }
34         if (flag == 0)
35         {
36             printf("YES\n");
37         }
38         else
39         {
40             printf("NO\n");
41         }
42     }
43     return 0;
44 }

 

posted @ 2019-12-06 11:38  jason2018  阅读(628)  评论(0编辑  收藏  举报