-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix 3x3.cpp
71 lines (49 loc) · 1.25 KB
/
matrix 3x3.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
#include <iostream>
using namespace std;
int main() {
int matrix1[3][3], matrix2[3][3], i, j, k;
int temp1, total[3][3];
cout<<"Enter 9 numbers in a 3x3 matrix: "<<endl;
for (i = 0; i <= 2; i++) {
for (j = 0; j <= 2; j++) {
cin>>matrix1[i][j];
}
}
cout<<"\nEnter 9 numbers in another 3x3 matrix: "<<endl;
for (i = 0; i <= 2; i++) {
for (j = 0; j <= 2; j++) {
cin>>matrix2[i][j];
}
}
cout<<"\nMatrix 1: "<<endl;
for (i = 0; i <= 2; i++) {
for (j = 0; j <= 2; j++) {
cout<<matrix1[i][j]<<" ";
}
cout<<endl;
}
cout<<"\nMatrix2: "<<endl;
for (i = 0; i <= 2; i++) {
for (j = 0; j <= 2; j++) {
cout<<matrix2[i][j]<<" ";
}
cout<<endl;
}
for (i = 0; i <= 2; i++) {
for (j = 0; j <= 2 ; j++) {
temp1 = 0;
for (k = 0; k <= 2; k++){
temp1 = temp1 + matrix1[i][k]*matrix2[k][j];
}
total[i][j] = temp1;
}
}
for (i = 0; i <= 2; i++) {
for (j = 0; j <= 2; j++) {
cout<<"\t";
cout<<" "<<total[i][j];
}
cout<<"\n";
}
return 0;
}