任务描述
求一个三行三列的转置矩阵。
输入格式:
第一行一个整数n<20,表示有n组测试数据,下面是n组数据;
每组测试数据是九个整型数(每个数都不大于10000),分别为矩阵的的每项;
输出格式:
每组测试数据的转置矩阵;请在每组输出之后加一个换行
输入样例:
2
1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 1
输出样例:
1 4 7
2 5 8
3 6 9
2 5 8
3 6 9
4 7 1
题目来源
该题目选自NYOJ网站,在线网址:http://nyoj.top/problem/29
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[3][3];
for(int t=0;t<n;t++)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
int temp;
temp=a[1][0];
a[1][0]=a[0][1];
a[0][1]=temp;
temp=a[2][0];
a[2][0]=a[0][2];
a[0][2]=temp;
temp=a[2][1];
a[2][1]=a[1][2];
a[1][2]=temp;
for(int j1=0;j1<3;j1++)
{
for(int j2=0;j2<3;j2++)
{
printf("%d ",a[j1][j2]);
}
printf("\n");
}
}
return 0;
}