C语言:计算两个矩阵的乘积,请问一下C程序错在哪儿啊?#includeint main(){int A[2][4]={1,2,3,4,5,6,7,8};int B[4][3]={1,2,3,4,5,6,7,8,9,10,11,12};int i,j,k;static int C[2][3];for(i=0; i
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 10:05:03
C语言:计算两个矩阵的乘积,请问一下C程序错在哪儿啊?#includeint main(){int A[2][4]={1,2,3,4,5,6,7,8};int B[4][3]={1,2,3,4,5,6,7,8,9,10,11,12};int i,j,k;static int C[2][3];for(i=0; i
C语言:计算两个矩阵的乘积,请问一下C程序错在哪儿啊?
#include
int main()
{
int A[2][4]={1,2,3,4,5,6,7,8};
int B[4][3]={1,2,3,4,5,6,7,8,9,10,11,12};
int i,j,k;
static int C[2][3];
for(i=0; i
C语言:计算两个矩阵的乘积,请问一下C程序错在哪儿啊?#includeint main(){int A[2][4]={1,2,3,4,5,6,7,8};int B[4][3]={1,2,3,4,5,6,7,8,9,10,11,12};int i,j,k;static int C[2][3];for(i=0; i
应该这样改:
#include<stdio.h>
# include <stdlib.h>
int main()
{
int A[2][4]={1,2,3,4,5,6,7,8};
int B[4][3]={1,2,3,4,5,6,7,8,9,10,11,12};
int i, j, k;
static int C[2][3];
for(i=0; i<2; i++)
{
for(j=0; j<3; j++)
{
for(k=0; k<4; k++)
{
C[i][j]=C[i][j]+A[i][k]*B[k][j];
}
printf("%5d",C[i][j]);//改动
}
printf("\n");//改动
}
system("pause");
}
你的想法很对,就是printf("%5d",C[i][j]);,k每变一次就printf一次很明显是错的.
结果如上我对了两个数字是对的