|1522|對稱矩陣的轉置
阿新 • • 發佈:2019-02-07
Problem Description
輸入矩陣的行數,再依次輸入矩陣的每行元素,判斷該矩陣是否為對稱矩陣,若矩陣對稱輸出“yes",不對稱輸出”no“。
Input
輸入有多組,每一組第一行輸入一個正整數N(N<=20),表示矩陣的行數(若N=0,表示輸入結束)。
下面依次輸入N行資料。
Output
若矩陣對稱輸出“yes",不對稱輸出”no”。
Example Input
3 6 3 12 3 18 8 12 8 7 3 6 9 12 3 5 8 12 6 3 0
Example Output
yes no
Hint
#include<stdio.h> #include<string.h> int main() { int n,i,j,f=0; int a[50][50]; while(scanf("%d",&n)==1) { if(n==0) { break; } for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } for(i=0;i<n;i++) { for(j=0;j<=i;j++) { if(a[i][j]!=a[j][i]) { f=1; break; } } } if(f==0) printf("yes\n"); else printf("no\n"); } return 0; }
Author
/*心得:迴圈和陣列學的還好
*/