矩阵乘法

· · 个人记录

#include<bits/stdc++.h>
using namespace std;
int n,k,m;
int a[105][105],b[105][105],c[105][105];
int main(){
    cin>>n>>k>>m;
    //输入a数组 
    for(int i=1;i<=n;i++)
        for (int j=1;j<=k;j++)
            cin>>a[i][j];
    //输入b数组 
    for(int i=1;i<=k;i++)
        for (int j=1;j<=m;j++)
            cin>>b[i][j];
    //求c数组 
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            for(int l=1;l<=k;l++)//枚举a第i行每个数 
                c[i][j]+=a[i][l]*b[l][j];
    //输出
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)
            cout<<c[i][j]<<" ";
        cout<<endl;}

    return 0;
}