zoukankan      html  css  js  c++  java
  • c语言510 求矩阵的乘积

    求3行4列矩阵和4行5列矩阵的乘积。

    1、

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

  • 相关阅读:
    常用模块
    二分查找算法
    递归函数
    文件操作
    day02--Python基础二(基础数据类型)
    Python学习笔记day01--Python基础
    Python2X和Python3X的区别
    testdisk修复文件系统
    机器学习入门 快速版
    tableau教程 快速入门
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14724074.html
Copyright © 2011-2022 走看看