题解 | #矩阵转置#
矩阵转置
https://www.nowcoder.com/practice/351b3d03e410496ab5a407b7ca3fd841
#include <stdio.h> #include <stdlib.h> int main() { int a, b; scanf("%d %d", &a, &b); int i, j, *arr; arr = (int*)malloc(sizeof(int) * a * b); for (i = 0; i < a * b; i++) { scanf("%d", arr + i); } for (j = 0; j < b; j++) { for (i = 0; i < a; i++) { printf("%d ", *(arr + i * b + j)); } printf("\n"); } return 0; }