#include<stdio.h>
#define M 3
#define N 2
#define S 3
void main()
{
int a[M][N] = {1,2,3,4,5,6};
int b[N][S] = {1,2,3,4,5,6};
int c[M][S]; // 答案为{9,12,15,19,26,33,29,40,51}
int i,j,k;
int sum = 0;
for(k=0; k<M; k++)
{
for(i=0; i<S; i++)
{
sum = 0;
for(j=0; j<N; j++)
{
sum += a[k][j]*b[j][i];
}
c[k][i] = sum;
}
}
for(k=0; k<M; k++)
{
for(i=0; i<S; i++)
{
printf("%4d", c[k][i]);
}
printf("\n");
}
}
两个矩阵相乘
最新推荐文章于 2021-05-18 19:20:21 发布