矩阵乘法程序纠错。。。

来源:百度知道 编辑:UC知道 时间:2024/07/08 11:21:05
程序如下:
#include <iostream>
using namespace std;

int main()
{
int i,j,k,c[2][3];
int a[2][4]={{1,0,3,-1},{2,1,0,2}};
int b[4][3]={{4,1,0},{-1,1,3},{2,0,1},{1,3,4}};
for(i=0;i<2;i++)
{
for(k=0;k<3;j++)
{
c[i][k]=0;
for(j=0;j<4;k++)
c[i][k]+=a[i][j]*b[j][k];
}
}

cout<<"矩阵相乘的结果为:"<<endl;
for(i=0;i<2;i++)
{
for(k=0;k<3;k++)
cout<<c[i][k]=" ";
cout<<endl;
}

return 0;
}

编译时提示错误:error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'char [2]' (or there is no acceptable conversion)
请问这是什么原因?

就你这个错误而言,是这句话错了
cout<<c[i][k]=" ";
应该写成
cout<<c[i][k]<<" ";

不过程序看了一下,矩阵乘法的过程好像也有问题.

cout<<c[i][k]=" "; 错了。

cout<<c[i][k]=" ";
改一下:
cout<<c[i][k]<<" ";