zoukankan      html  css  js  c++  java
  • c语言中计算矩阵的乘积

    c语言中计算矩阵的乘积。

    矩阵相乘的条件:左侧矩阵的列数等于右侧矩阵的行数。

    矩阵相乘的结果:行数为左侧矩阵的行数,列数为右侧矩阵的列数。

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, k, a[4][6], b[6][7], c[4][7] = {0};
        puts("please input the elements of matrix a.");
        for(i = 0; i < 4; i++)
        {
            for(j = 0; j < 6; j++)
            {
                printf("a[%d][%d] = ", i, j); scanf("%d", &a[i][j]);
            }
        }
        puts("\nshow the matrix for of matrix a.");
        for(i = 0; i < 4; i++)
        {
            for(j = 0; j < 6; j++)
            {
                printf("%4d", a[i][j]);
            }
            putchar('\n');
        }
        
        puts("\nplease input the elements of matrix b.");
        for(i = 0; i < 6; i++)
        {
            for(j = 0; j < 7; j++)
            {
                printf("b[%d][%d] = ", i, j); scanf("%d", &b[i][j]);
            }
        }
        puts("\nshow the matrix form of matrix b.");
        for(i = 0; i < 6; i++)
        {
            for(j = 0; j < 7; j++)
            {
                printf("%4d", b[i][j]);
            }
            putchar('\n');
        }
        
        puts("\n===================================");
        for(i = 0; i < 4; i++)
        {
            for(j = 0; j < 7; j++)
            {
                for(k = 0; k < 6; k++)
                {
                    c[i][j] += a[i][k] * b[k][j];
                }
            }    
        }
        puts("show the product of the two matrixes.");
        for(i = 0; i < 4; i++)
        {
            for(j = 0; j < 7; j++)
            {
                printf("%4d", c[i][j]);
            }
            putchar('\n');
        }
        return 0;
    }

  • 相关阅读:
    JS Function Arguments
    C# CuttingEdge.Conditions 验证帮助类库 文档翻译
    JS AngualrJs 指令
    每日踩坑 2018-06-19 AutoMapper简单性能测试
    C# 集合类-使用
    工具 EZDML表结构设计器
    unittest的discover方法
    转:unittest的几种运行方式
    unittest学习5-断言
    unittest学习4-跳过用例执行
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14727072.html
Copyright © 2011-2022 走看看