-
Notifications
You must be signed in to change notification settings - Fork 0
/
08-e12B.c
42 lines (28 loc) · 852 Bytes
/
08-e12B.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// transpose variable size matrix function, 08-e12A modified
#include <stdio.h>
int main(void) {
void transposeMatrix(int x, int y, int A[y][x], int B[x][y]);
int x, y, i, j;
printf("dimensions (rows, columns): ");
scanf("%i %i", &y, &x);
int A[y][x], B[x][y];
printf("\noriginal matrix:\n");
for (i = 0; i < y; i++) {
for (j = 0; j < x; j++) {
A[i][j] = i + 1;
printf("%2i ", A[i][j]);
}
printf("\n");
}
transposeMatrix(x, y, A, B);
printf("\ntransposed matrix:\n");
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) printf("%2i ", B[i][j]);
printf("\n");
}
return 0;
}
void transposeMatrix(int x, int y, int A[y][x], int B[x][y]) {
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++) B[i][j] = A[j][i];
}