From a39951d8f69209cfea2b7051832b851914e662ef Mon Sep 17 00:00:00 2001 From: rodri Date: Sat, 22 Feb 2020 09:56:09 +0000 Subject: now version controlled. --- matrixmul.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 matrixmul.c (limited to 'matrixmul.c') diff --git a/matrixmul.c b/matrixmul.c new file mode 100644 index 0000000..c2da272 --- /dev/null +++ b/matrixmul.c @@ -0,0 +1,53 @@ +#include +#include + +typedef double Matrix[4][4]; + +void +mulm(Matrix a, Matrix b) +{ + int i, j, k; + Matrix r; + + for(i = 0; i < 4; i++) + for(j = 0; j < 4; j++){ + r[i][j] = 0; + for(k = 0; k < 4; k++) + r[i][j] += a[i][k]*b[k][j]; + } + for(i = 0; i < 4; i++) + for(j = 0; j < 4; j++) + a[i][j] = r[i][j]; +} + +void +printm(Matrix m) +{ + int i, j; + + for(i = 0; i < 4; i++){ + for(j = 0; j < 4; j++) + print("%g\t", m[i][j]); + print("\n"); + } +} + +void +main() +{ + Matrix m1 = { + 1, 2, -1, 0, + 2, 0, 1, 0, + 0, 0, 0, 0, + 0, 0, 0, 0 + }; + Matrix m2 = { + 3, 1, 0, 0, + 0, -1, 0, 0, + -2, 3, 0, 0, + 0, 0, 0, 0 + }; + mulm(m1, m2); + printm(m1); + exits(0); +} -- cgit v1.2.3