题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
#include <stdio.h> int main() { int x, y, z; while (scanf("%d\n%d\n%d", &x, &y, &z) != EOF) { int A[x][y], B[y][z], C[x][z]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { scanf("%d", &A[i][j]); } } for (int i = 0; i < y; i++) { for (int j = 0; j < z; j++) { scanf("%d", &B[i][j]); } } for (int i = 0; i < x; i++) { for (int j = 0; j < z; j++) { int sum = 0; for (int k = 0; k < y; k++) { sum += A[i][k] * B[k][j]; } C[i][j] = sum; } } for (int i = 0; i < x; i++) { for (int j = 0; j < z; j++) { printf("%d ",C[i][j]); } printf("\n"); } } return 0; }