问答题
计算两个矩阵的乘积。程序如下,请填空。
说明:
①当矩阵A的列数等于矩阵B的行数时,A与B可以相乘得到矩阵C。
②矩阵C的行数等于矩阵A的行数,C的列数等于B的列数。
③矩阵C的第m行第n列的元素等于矩阵A的第m行的元素与矩阵B的第n列对应元素乘积之和。
#include
#define M 2
#define P 3
#define N 4
void fun(int a[M][P],int b[P][N],int c[M][N])
{
int i,j,k,s;
for([填空(1)] )
{
for([填空(2)] )
{
s=[填空(3)] ;
for(k=0;k
s+=[填空(4)] ;
c[i][j]=s;
}
}
}
int main()
{
int a[M][P],b[P][N],c[M][N];
int i,j,k;
printf(“Input array a[2][3];”); //输入数组A的值
for([填空(5)] )
{
for([填空(6)] )
scanf(“%d”,&a[i][k]);
}
printf(“Input array b[3][4];”); //输入数组B的值
for([填空(7)] )
{
for([填空(8)] )
scanf(“%d”,&b[i][k]);
}
fun(a,b,c);
printf(“Output array c[2][4]:”); //输出数组C的值
for(i=0;i
{
for(j=0;j
{
printf(“%5d”,c[i][j]);
}
printf(“”);
}
return 0;
}