题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
#include <cstring> #include <iostream> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; int a[x][y]; int b[y][z]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for (int i = 0;i < x;i++) { for (int j = 0;j < y;j++) { cin >> a[i][j]; } } for (int i = 0;i < y;i++) { for (int j = 0;j < z;j++) { cin >> b[i][j]; } } int c[x][z]; memset(c, 0, sizeof(c)); for (int i = 0; i < x; i++) { for (int j = 0; j < z; j++) { for (int k = 0; k < y; k++) { c[i][j] += a[i][k] * b[k][j]; } } } for (int i = 0;i < x;i++) { for (int j = 0;j < z;j++) { cout << c[i][j] << ' '; } cout << endl; } } // 64 位输出请用 printf("%lld")