7-題解

========================================================= 基礎級-7-(1-2)題解 - (飆程式網分站) --------------------------------------------------------- 7-1 --------------------------------------------------------- #include <cstdio> int main() { int n;scanf("%d",&n); int a[n*n],i,j; for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&a[i*n+j]); for(i=0;i<n;i++) { for(j=0;j<n;j++) printf("%d ",a[j*n+i]); printf("\n"); } return 0; } --------------------------------------------------------- 7-2 --------------------------------------------------------- #include<cstdio> int main() { int n; scanf("%d",&n); int a[n][n],b[n][n]; for(int i=0;i<n;i++)for(int j=0;j<n;j++)scanf("%d",&a[i][j]); for(int i=0;i<n;i++)for(int j=0;j<n;j++)scanf("%d",&b[i][j]); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { int m=0; for(int k=0;k<n;k++)m+=a[i][k]*b[k][j]; printf("%d ",m); } printf("\n"); } } ---------------------------------------------------------