
This is no more than a matrix transpose. Read in one order (e.g., by rows) and then output in the other (e.g., by columns):
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fin = fopen ("rowcol.in", "r");
FILE *fout = fopen ("rowcol.out", "w");
int r, c, i, j;
int x[20][20];
fscanf (fin, "%d %d", &r, &c);
for (i = 0; i < c; i++)
for (j = 0; j < r; j++)
fscanf (fin, "%d", &x[j][i]);
for (j = 0; j < r; j++)
for (i = 0; i < c; i++)
fprintf(fout, "%d\n", x[j][i]);
exit (0);
}