BUPT-homework/pset11/2-1-transpose.c

35 lines
730 B
C
Raw Normal View History

2021-12-02 21:04:43 +08:00
#include <stdio.h>
#pragma gcc optimize("O2")
#define MAX 100
void transpose(int matrix[][MAX], int result[][MAX], int n, int m);
int main(void) {
int n, m;
scanf("%d%d", &n, &m);
int matrix[MAX][MAX];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &matrix[i][j]);
}
}
int result[MAX][MAX];
transpose(matrix, result, n, m);
for (int i = 0; i < m; i++) {
for (int j = 0; j < n - 1; j++) {
printf("%d ", result[i][j]);
}
printf("%d\n", result[i][n - 1]);
}
return 0;
}
void transpose(int matrix[][MAX], int result[][MAX], int n, int m) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
result[j][i] = matrix[i][j];
}
}
}