• 【C语言】矩阵相乘


    编程计算2×3阶矩阵A和3×2阶矩阵B之积C。
    要求:
    (1)从键盘分别输入矩阵A和B,
      输出乘积矩阵C
    (2) 
    **输入提示信息为: 
    输入矩阵A之前提示:"Input 2*3 matrix a:
    "
    输入矩阵B之前提示:"Input 3*2 matrix b:
    "
    **输入矩阵中每个值的格式为:"%d"
    **输出格式为:
    输出矩阵C之前提示:"Results:
    "
    输出矩阵C中每个值的格式:"%6d"
    输出矩阵C各行结束时换行
     1 #include<stdio.h>
     2 main()
     3 {
     4     int a[2][3], b[3][2], c[2][2], i, j, k;
     5     printf("Input 2*3 matrix a:
    ");
     6     for (i = 0; i < 2; i++)
     7     {
     8         for (j = 0; j < 3; j++)
     9         {
    10             scanf("%d", &a[i][j]);
    11         }
    12     }
    13     printf("Input 3*2 matrix b:
    ");
    14     for (i = 0; i < 3; i++)
    15     {
    16         for (j = 0; j < 2; j++)
    17         {
    18             scanf("%d", &b[i][j]);
    19         }
    20     }
    21     for (i = 0; i < 2; i++)
    22     {
    23         for (j = 0; j < 2; j++)
    24         {
    25             c[i][j] = 0;
    26             for (k = 0; k < 3; k++)
    27             {
    28                 c[i][j] += a[i][k] * b[k][j];
    29             }
    30         }
    31     }
    32     printf("Results:
    ");
    33     for (i = 0; i < 2; i++)
    34     {
    35         for (j = 0; j < 2; j++)
    36         {
    37             printf("%6d", c[i][j]);
    38         }
    39         printf("
    ");
    40     }
    41 }
    
    
    
     
  • 相关阅读:
    HDU 1009 FatMouse' Trade
    HDU 2602 (简单的01背包) Bone Collector
    LA 3902 Network
    HDU 4513 吉哥系列故事——完美队形II
    LA 4794 Sharing Chocolate
    POJ (Manacher) Palindrome
    HDU 3294 (Manacher) Girls' research
    HDU 3068 (Manacher) 最长回文
    Tyvj 1085 派对
    Tyvj 1030 乳草的入侵
  • 原文地址:https://www.cnblogs.com/20201212ycy/p/14904521.html
Copyright © 2020-2023  润新知