1、创建一个函数,将4行3列矩阵和3行4l.ie矩阵b的乘积,存储在4行4列矩阵c中。
#include <stdio.h>
void mat_mul(int x[4][3], int y[3][4], int z[4][4])
{
int i, j, k;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
z[i][j] = 0;
for (k = 0; k < 3; k++)
{
z[i][j] += x[i][k] * y[k][j];
}
}
}
}
void mat_print(int x[4][4])
{
int i, j;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
printf("%4d", x[i][j]);
}
putchar('\n');
}
}
int main(void)
{
int a[4][3] = {{4,2,3},{5,1,2},{3,4,2},{1,3,6}};
int b[3][4] = {{2,4,3,1},{2,1,3,4},{5,2,4,3}};
int c[4][4];
mat_mul(a, b, c);
puts("view the product.");
mat_print(c);
return 0;
}