题解 | #计算两个矩阵的乘积#
计算两个矩阵的乘积
https://www.nowcoder.com/practice/ed6552d03e624ba58d16af6d57e1c3e9
#include <stdio.h> int main(){ int matrix1[2][3]; int matrix2[3][2]; //输入 for (int i = 0; i < 2; ++i) { for (int j = 0; j < 3; ++j) { scanf("%d", &matrix1[i][j]); } } for (int i = 0; i < 3; ++i) { for (int j = 0; j < 2; ++j) { scanf("%d", &matrix2[i][j]); } } //计算 int result[2][2]; int temp = 0; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 3; ++k) { temp += matrix1[i][k] * matrix2[k][j]; } result[i][j] = temp; temp = 0; } } for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { printf("%d ", result[i][j]); } printf("\n"); } return 0; }