📜  C中实现矩阵乘法

📅  最后修改于: 2020-10-23 01:08:59             🧑  作者: Mango

C中的矩阵乘法

C语言中的矩阵乘法:我们可以对2个矩阵进行加,减,乘和除运算。为此,我们从用户那里获取行号,列号,第一矩阵元素和第二矩阵元素的输入。然后,我们对用户输入的矩阵执行乘法运算。

在矩阵乘法中,将第一矩阵的一个行元素与第二矩阵的所有列元素相乘。

让我们尝试通过下图了解2 * 2和3 * 3矩阵的矩阵乘法:

我们来看一下C语言中的矩阵乘法程序。

#include  
#include
int main(){
    int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;  
    system("cls");
    printf("enter the number of row=");  
    scanf("%d",&r);  
    printf("enter the number of column=");  
    scanf("%d",&c);  
    printf("enter the first matrix element=\n");  
    for(i=0;i

输出:

enter the number of row=3
enter the number of column=3
enter the first matrix element=
1 1 1
2 2 2
3 3 3
enter the second matrix element=
1 1 1
2 2 2
3 3 3
multiply of the matrix=
6 6 6
12 12 12
18 18 18

让我们尝试通过下图了解3 * 3和3 * 3矩阵的矩阵乘法: