从键盘输入4×3的一个矩阵,转置为3×4的矩阵并输出。用c语言
时间: 2024-05-09 08:15:39 浏览: 30
以下是一个示例代码,可以实现输入4x3矩阵,转置为3x4矩阵并输出:
```c
#include <stdio.h>
int main() {
int matrix[4][3], transpose[3][4];
int i, j;
// 输入4x3矩阵
printf("Enter the elements of the matrix:\n");
for (i = 0; i < 4; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &matrix[i][j]);
}
}
// 转置为3x4矩阵
for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) {
transpose[i][j] = matrix[j][i];
}
}
// 输出3x4矩阵
printf("Transpose of the matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) {
printf("%d ", transpose[i][j]);
}
printf("\n");
}
return 0;
}
```
运行示例:
```
Enter the elements of the matrix:
1 2 3
4 5 6
7 8 9
10 11 12
Transpose of the matrix:
1 4 7 10
2 5 8 11
3 6 9 12
```