1、c语言中计算4行3列矩阵和3行4列矩阵的乘积
#include <stdio.h>
int main(void)
{
int i, j, k;
int a[4][3], b[3][4];
puts("input the array a.");
for (i = 0; i < 4; i++)
{
for (j = 0; j < 3; j++)
{
printf("a[%d][%d] = ", i, j);
scanf("%d", &a[i][j]);
}
}
puts("input the array b.");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 4; j++)
{
printf("a[%d][%d] = ", i, j);
scanf("%d", &b[i][j]);
}
}
puts("calculate the conduct.");
int c[4][4];
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
c[i][j] = 0;
for (k = 0; k < 3; k++)
{
c[i][j] += a[i][k] * b[k][j];
}
}
}
puts("view the product.");
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
printf("%4d", c[i][j]);
}
putchar('\n');
}
return 0;
}