//矩阵相乘:
#include<iostream>
using namespace std;
#define size_m 2
#define size_n 3
#define size_s 4
//void mulmatrix(int** matrixA, int** matrixB, int** matrixC, int n)
//{
// for (int i = 0; i < n; i++)
// {
// for (int j = 0; j < n; j++)
// {
//
// matrixC[i][j] = 0;
// for (int k = 0; k < n; k++)
// {
// matrixC[i][j] += matrixA[i][k] * matrixB[k][j];
// }
// }
// }
//}
//测试程序:
int main()
{
int i;
int j;
int s1[size_m][size_n] = { { 1, 2, 3 }, { 2, 3, 4 } };
int s2[size_n][size_s] = { { 1, 2, 3, 4 }, { 2, 3, 4, 5 }, { 3, 4, 5, 6 } };
int s3[size_n][size_s];
for (i = 0; i < size_m; i++)
{
for (j = 0; j < size_n; j++)
{
s3[i][j] = 0;
for (int k = 0; k < size_s; k++)
{
s3[i][j] +=s1[i][k] * s2[k][j];
}
}
}
for (i = 0; i < size_m; ++i)
{
for (j = 0; j < size_s; ++j)
{
cout << s3[i][j] << " ";
}
cout << endl;
}
return 0;
}
#include<iostream>
using namespace std;
#define size_m 2
#define size_n 3
#define size_s 4
//void mulmatrix(int** matrixA, int** matrixB, int** matrixC, int n)
//{
// for (int i = 0; i < n; i++)
// {
// for (int j = 0; j < n; j++)
// {
//
// matrixC[i][j] = 0;
// for (int k = 0; k < n; k++)
// {
// matrixC[i][j] += matrixA[i][k] * matrixB[k][j];
// }
// }
// }
//}
//测试程序:
int main()
{
int i;
int j;
int s1[size_m][size_n] = { { 1, 2, 3 }, { 2, 3, 4 } };
int s2[size_n][size_s] = { { 1, 2, 3, 4 }, { 2, 3, 4, 5 }, { 3, 4, 5, 6 } };
int s3[size_n][size_s];
for (i = 0; i < size_m; i++)
{
for (j = 0; j < size_n; j++)
{
s3[i][j] = 0;
for (int k = 0; k < size_s; k++)
{
s3[i][j] +=s1[i][k] * s2[k][j];
}
}
}
for (i = 0; i < size_m; ++i)
{
for (j = 0; j < size_s; ++j)
{
cout << s3[i][j] << " ";
}
cout << endl;
}
return 0;
}