对于作业,我必须编写一个MatrixProduct.cpp
,它必须能够将两个1维c ++数组相乘。我写了一个方法multipoly
,它应该乘以两个1d数组,但它不会。我是C ++的新手,所以不要太难我。
double* multiply(double m1i[], double m2i[], int s1, int s2, int s3) {
double* matrixa = new double[s1*s2];
double* matrixb = new double[s2*s3];
double* matrixc = new double[s1*s3];
double sum;
for (int i = 0; i < (s1 * s2); i++)
{
for (int j = 0; j < s3; j++)
{
float sum = 0;
for (int k = 0; k < s2; k++)
{
sum = sum + matrixa[i] * matrixb[((k - 1) * s3) + (j - 1)];
matrixc[i * s3 + k] = sum;
}
}
}
cout << endl;
return matrixc;
}
感谢您的帮助:D