Matrix Multiplication, matrix multiplication Formula
1 # include <stdio. h> 2 3 // macro definition 4 # define max_row 200 // defines the maximum number of rows in the Matrix 5 # define max_column 200 // defines the maximum number of columns in the Matrix 6 7 int main () 8 {9 int I, j, k; 10 int m, s, n; // records the number of rows and columns of the matrix A, B, and C: matrix A: m * s; matrix B: s * n; matrix C: m * n 11 int A [max_row] [max_column], B [max_row] [max_column], C [max_row] [max_column] ={{ 0}, {0 }}; // three two-dimensional arrays, record matrices A, B, and C 12 13 // enter 14 scanf ("% d", & m, & s, & n ); // input row and column 15 for (I = 0; I <m; I ++) // input matrix A 16 for (j = 0; j <s; j ++) 17 scanf ("% d", & A [I] [j]); 18 for (I = 0; I <s; I ++) // input matrix B 19 for (j = 0; j <n; j ++) 20 scanf ("% d", & B [I] [j]); 21 22 // multiply the matrix by 23 for (I = 0; I <m; I ++) 24 for (j = 0; j <n; j ++) 25 for (k = 0; k <s; k ++) 26 C [I] [j] + = A [I] [k] * B [k] [j]; // matrix C should be m row n column, where C (I, j) is equal to the Inner Product 27 28 of the row vector of matrix A and the vector of column j of matrix B // output 29 for (I = 0; I <m; I ++) 30 {31 for (j = 0; j <n; j ++) 32 printf ("% d", C [I] [j]); 33 putchar ('\ n'); 34} 35 36 return 0; 37}