-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.cpp
79 lines (74 loc) · 1.41 KB
/
3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<iostream>
#include<random>
using namespace std;
/*
int main()
{
int A[10][10] = { 0 }, B[10][10] = { 0 }, result[10][10] = { 0 };
int row1, col1;
int row2, col2;
static default_random_engine e;
static uniform_int_distribution<int> u(0, 10);
cout << "请输入A矩阵的行数和列数(小于10):";
cin >> row1 >> col1;
for (int i = 0; i < row1; ++i)
{
for (int j = 0; j < col1; ++j)
{
A[i][j] = u(e);
}
}
cout << "\n" << endl;
cout << "请输入B矩阵的行数和列数(小于10):";
cin >> row2 >> col2;
for (int i = 0; i < row2; ++i)
{
for (int j = 0; j < col2; ++j)
{
B[i][j] = u(e);
}
}
cout << "A矩阵 = " << endl;
for (int i = 0; i < row1; ++i)
{
for (int j = 0; j < col1; ++j)
{
cout << A[i][j] << "\t";
}
cout << endl;
}
cout << endl << "B矩阵 = " << endl;
for (int i = 0; i < row2; ++i)
{
for (int j = 0; j < col2; ++j)
{
cout << B[i][j] << "\t";
}
cout << endl;
}
if (col1 == row2) //第一个矩阵的列数与第二个矩阵的行数相等时,两个矩阵才能相乘;
{
for (int i = 0; i < row1; i++) //a的行数
{
for (int j = 0; j < col2; j++) //b的列数
{
for (int k = 0; k < col1; k++) //a的列数
{
result[i][j] += A[i][k] * B[k][j];
}
}
}
cout << "结果为 result = " << endl;
for (int i = 0; i < row1; ++i)
{
for (int j = 0; j < col2; ++j)
{
cout << result[i][j] << "\t";
}
cout << endl;
}
}
else
cout << "行列数不匹配\n";
}
*/