[算法] 矩阵相乘
#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; int a[2][3] = {{100, 200, 300}, {400, 500, 600}}; int b[3][2] = {{1, 2}, {3, 4}, {5, 6}}; int c[2][2]; void solve(int m, int n) { for(int i = 0; i < m; ++i) { for(int j = 0; j < m; j++) { for(int k = 0; k < n; k++) { c[i][j] += a[i][k]*b[k][j]; } } } for(int i = 0; i < m; ++i) { for(int j = 0; j < m; ++j) { cout << c[i][j] << ' '; } cout << endl; } } int main() { solve(2, 3); return 0; }