#include int M1[4][2] = { {1,2}, {3,4}, {5,6}, {7,8}}; int M2[2][8] = { {1,2,3,4,5,6,7,8}, {1,2,3,4,5,6,7,8}}; int M3[4][8]; main() { int i,j; matrix_multiply(4,2,M1,2,8,M2,M3); for (i = 0; i < 4; i++) { for (j = 0; j < 8; j++) printf("%d ",M3[i][j]); printf("\n"); } } matrix_multiply(r1,c1,A,r2,c2,B,C) int r1; /* num of rows of first matrix */ int c1; /* num of columns of first matrix */ int r2; /* num of rows of second matrix */ int c2; /* num of columns of second matrix */ int A[4][2], B[2][8]; /* first and second matrix */ int C[4][8]; /* result matrix */ { int i,j; for (i = 0; i < r1; i++) for (j = 0; j < c2; j++) C[i][j] = inner_product(i,c1,A,j,r2,B); } inner_product(row,num_columns, M, column, num_rows, N) int row; /* row of first matrix used in inner product */ int column; /* column of second matrix used in inner product */ int num_rows, num_columns; /* num of rows and columns of first and second matrix respectively */ int M[4][2], N[2][8]; /* first and second matrix */ { int sum = 0; int i; if (num_columns != num_rows) { printf("Error! num_columns (%d) != num_rows (%d)\n", num_columns, num_rows); exit(-1); } else for (i = 0; i < num_columns; i++) sum += M[row][i] * N[i][column]; return(sum); }