题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
#include <stdio.h> #include <string.h> int main() { int row1, col1, col2; scanf("%d\n%d\n%d", &row1, &col1, &col2); int mat1[row1][col1], mat2[col1][col2]; int sum[row1][col2]; memset(sum, 0, sizeof(sum)); int i, j; for (i = 0; i < row1; i++) { for (j = 0; j < col1; j++) { scanf("%d", &mat1[i][j]); } } for (i = 0; i < col1; i++) { for (j = 0; j < col2; j++) { scanf("%d", &mat2[i][j]); } } for(i=0;i<row1;i++) { for (j=0; j<col2;j++) { for(int k =0;k<col1;k++) { sum[i][j]+=mat1[i][k]*mat2[k][j]; } } } for(i=0;i<row1;i++) { for(j=0;j<col2;j++) { printf("%d ",sum[i][j]); } printf("\n"); } }