codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <stdio.h> #define M 3 #define N 2 void dump_mat(double *p, int m, int n) { int i, j; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) printf("%.2f ", *p++); putchar('\n'); } putchar('\n'); } void MatProduct(int mm, int nn, double a[][N], double b[][M], double c[][M]) { int m, n, k; for(n = 0; n < mm; n++) for(m = 0; m < mm; m++) { c[m][n] = 0.0; for(k = 0; k < nn; k++) c[m][n] += a[m][k] * b[k][n]; } } int main() { static double x[M][N] = { {1, 2}, {3, 4}, {5, 6} }; static double y[N][M] = { {1, 2, 3}, {4, 5, 6} }; static double z[M][M]; printf("x:\n"); dump_mat(&x[0][0], M, N); printf("y:\n"); dump_mat(&y[0][0], N, M); MatProduct(M, N, x, y, z); printf("z:\n"); dump_mat(&z[0][0], M, M); return 0; } /* end */
Private
[
?
]
Run code
Submit