题解 | #矩阵乘法#

矩阵乘法

https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b

#include <iostream>

using namespace std;

#define fas(i,a,b) for(int i=a;i<b;++i)


const int NUM=100;
int m1[NUM][NUM];
int m2[NUM][NUM];
//int m3[NUM][NUM];

int main()
{
    int m,n,k;
    while(cin>>m>>n>>k)
    {
        fas(i,0,m)
            fas(j,0,n)
                cin>>m1[i][j];
        fas(i,0,n)
            fas(j,0,k)
                cin>>m2[i][j];
        // cout<<"********************************"<<endl;
        // // fas(i,0,n)
        // // {
        // //     fas(j,0,n)
        // //         cout<<m1[i][j]<<" ";
        // //     cout<<endl;
        // // }
        // cout<<"********************************"<<endl;
        fas(i,0,m)
        {
            fas(j,0,k)
            {
                int tmp=0;
                fas(i1,0,n)
                {
                    tmp+=m1[i][i1]*m2[i1][j];
                }
                //m3[i][j]=tmp;
                cout<<tmp<<" ";
            }
            cout<<endl;
        }
        //display matrix
        // fas(i,0,m)
        // {
        //     fas(j,0,k)
        //         cout<<m3[i][j]<<" ";
        //     cout<<endl;
        // }
        


    }
        
}

全部评论

相关推荐

07-01 13:37
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
06-11 17:39
门头沟学院 Java
小呆呆的大鼻涕:卧槽,用户彻底怒了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务