-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path#11 (3) - Check Matrices Equality.txt
More file actions
74 lines (61 loc) · 1.43 KB
/
Copy path#11 (3) - Check Matrices Equality.txt
File metadata and controls
74 lines (61 loc) · 1.43 KB
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
#include<iostream>
#include<iomanip>
using namespace std;
short RandomNumber(short From, short To)
{
short RandNum = rand() % (To - From + 1) + From;
return RandNum;
}
void FillMatrixWithRandomNumbers(short Arr[3][3], short Rows, short Columns)
{
for (short i = 0;i < Rows;i++)
{
for (short j = 0;j < Columns;j++)
{
Arr[i][j] = RandomNumber(1,10);
}
}
}
void PrintMatrix(short Arr[3][3], short Rows, short Columns)
{
for (short i = 0;i < Rows;i++)
{
for (short j = 0;j < Columns;j++)
{
printf("%0*d\t", 2, Arr[i][j]);
}
cout << endl;
}
}
short SumOfMatrix(short Matrix1[3][3], short Rows, short Columns)
{
short SumMatrix = 0;
for (short i=0;i<Rows;i++)
{
for (short j = 0;j < Rows;j++)
{
SumMatrix += Matrix1[i][j];
}
}
return SumMatrix;
}
bool AreEqualMatrices(short Matrix1[3][3], short Matrix2[3][3], short Rows, short Columns)
{
return (SumOfMatrix(Matrix1,3,3) == SumOfMatrix(Matrix2, 3, 3));
}
int main()
{
srand((unsigned)time(NULL));
short Matrix1[3][3], Matrix2[3][3];
FillMatrixWithRandomNumbers(Matrix1, 3, 3);
FillMatrixWithRandomNumbers(Matrix2, 3, 3);
cout << "Matrix 1 :\n";
PrintMatrix(Matrix1, 3, 3);
cout << "Matrix 2 :\n";
PrintMatrix(Matrix2, 3, 3);
if (AreEqualMatrices(Matrix1, Matrix2, 3, 3))
cout << "\nYes: both Matrices are Equal\n";
else
cout << "\nNo: Matrices are Not Equal\n";
return 0;
}