题解 | #计算两个矩阵的乘积#

计算两个矩阵的乘积

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

#include <cstdio>
using namespace std;
int main() {
    int x1[2][3];
    for (int i = 0; i <= 1; i++) {
        for (int j = 0; j <= 2; j++) {
            scanf("%d", &x1[i][j]);
        }
    }
    int x2[3][2];
    for (int i = 0; i <= 2; i++) {
        for (int j = 0; j <= 1; j++) {
            scanf("%d", &x2[i][j]);
        }
    }
    int x3[2][2];
    int sum = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 3; k++) {
                sum = sum + x1[i][k] * x2[k][j];
            }
            x3[i][j] = sum;
            sum = 0;
        }
    }
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            printf("%d ", x3[i][j]);
        }
        printf("\n");
    }

}

全部评论

相关推荐

今天 11:21
门头沟学院 Java
总包48.5w,意想不到的价格
无情咸鱼王的秋招日记之薛定谔的Offer:R
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务