using namespace std;
void chengfa(int, int, int, int[], int[]);
class juzhen
{
public:
int m;
int n;
int* arr;
juzhen(){arr = new int[m*n]; };
~juzhen()
{
delete[]arr;
};
void output()
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << arr[j + i*n] << "\t";
}
cout << endl;
}
}
void creat()
{
cout << "请输入矩阵行数:";
cin >> m;
cout << "请输入矩阵列数:";
cin >> n;
cout << "您将输入一个" << m << "X" << n << "的矩阵" << endl;
for (int i = 0; i < m; i++)
{
cout << "请输入第" << i + 1 << "行数据:\n";
for (int j = 0; j < n; j++)
{
cin >> arr[j + i*n];
}
}
}
};
int main()
{
cout << "第一个矩阵" << endl;
juzhen ju1;
ju1.creat();
ju1.output();
cout << "第二个矩阵" << endl;
juzhen ju2;
ju2.creat();
ju2.output();
if (ju1.n != ju2.m){ cout << "数组格式不正确!已终止程序!" << endl; return 0; }
cout << "矩阵1乘矩阵2为:"<
system("pause");
delete[]ju1.arr;
delete[]ju2.arr;
}
void chengfa(int m1, int n, int m2, int arr1[], int arr2[])
{
for (int i = 0; i < m1; i++)
{
for (int j = 0; j < n; j++)
{
static int sum;
for (int p = 0; p < m2; p++)
{
sum += arr1[p + i*m2] * arr2[p*n + j];
}
cout << sum << "\t";
sum = 0;
}
cout << endl;
}
}