Transpose

Lab C Intermediate 20 points

Read an r×c matrix and print its transpose.

Input

r c, then r rows.

Output

c rows.

Example

Input

2 3
1 2 3
4 5 6

Output

1 4
2 5
3 6
Sample input available Sample output available
Editor
C

Hints

Print column j of the original as row j.

Solution explanation

Element (i, j) becomes (j, i).

Show solution
#include <stdio.h>

int main() {
    int r, c, m[10][10];
    scanf("%d %d", &r, &c);
    for (int i = 0; i < r; i++)
        for (int j = 0; j < c; j++)
            scanf("%d", &m[i][j]);
    for (int j = 0; j < c; j++) {
        for (int i = 0; i < r; i++) {
            printf("%d%s", m[i][j], i < r - 1 ? " " : "\n");
        }
    }
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD