题解 | #计算两个矩阵的乘积#
计算两个矩阵的乘积
https://www.nowcoder.com/practice/ed6552d03e624ba58d16af6d57e1c3e9
#include <cstdio> using namespace std; int main() { int x1[2][3]; for (int i = 0; i <= 1; i++) { for (int j = 0; j <= 2; j++) { scanf("%d", &x1[i][j]); } } int x2[3][2]; for (int i = 0; i <= 2; i++) { for (int j = 0; j <= 1; j++) { scanf("%d", &x2[i][j]); } } int x3[2][2]; int sum = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 3; k++) { sum = sum + x1[i][k] * x2[k][j]; } x3[i][j] = sum; sum = 0; } } for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { printf("%d ", x3[i][j]); } printf("\n"); } }