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
43
44
45
46
47
48
49
|
#include <u.h>
#include <libc.h>
#define N 4
typedef double Matrix[N][N];
void
transpose(Matrix a)
{
int i, j;
double tmp;
for(i = 0; i < N; i++)
for(j = i; j < N; j++){
tmp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = tmp;
}
}
void
printm(Matrix m)
{
int i, j;
for(i = 0; i < N; i++){
for(j = 0; j < N; j++)
print("%g ", m[i][j]);
print("\n");
}
print("\n");
}
void
main()
{
Matrix m = {
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44,
};
printm(m);
transpose(m);
printm(m);
exits(0);
}
|