codeup之矩阵转置
Description
将一个2行3列的矩阵(二维数组)行列互换,存储到另一个3行2列的矩阵中。
要求以整型数据为例来解答。
Input
输入2行数据,每行3个整数,以空格分隔。
Output
行列互换后的矩阵,3行,每行2个数据,以空格分隔。
Sample Input Copy
1 2 3
4 5 6
Sample Output Copy
1 4
2 5
3 6
solution
#include <stdio.h>
int main(){
int a[3][2];
for(int i = 0; i < 2; i++)
for(int j = 0; j < 3; j++)
scanf("%d", &a[j][i]);
for(int i = 0; i < 3; i++){
for(int j = 0; j < 2; j++)
printf("%d ", a[i][j]);
printf("\n");
}
return 0;
}