-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP76MATRIX.cpp
More file actions
60 lines (51 loc) · 1.28 KB
/
P76MATRIX.cpp
File metadata and controls
60 lines (51 loc) · 1.28 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
// Matrix Multiplication
#include<iostream>
using namespace std;
int main(){
int n1,n2,n3;
cout<<"Enter the order of matrix: ";
cin>>n1>>n2>>n3;
int m1[n1][n2]; // --> defining 2d array for n1 * n2
int m2[n2][n3];
for (int i = 0; i < n1; i++)
{
for (int j = 0; j < n2; j++)
{
cin >> m1[i][j]; // taking input of 1st 2d array
}
}
for (int i = 0; i < n2; i++)
{
for (int j = 0; j < n3; j++)
{
cin >> m2[i][j];
}
}
int ans[n1][n3];
for (int i = 0; i < n1; i++)
{
for (int j = 0; j < n3; j++)
{
ans[i][j]=0;
}
}
for (int i = 0; i < n1; i++) // in matrix 1 we are iterating through all the rows
{
for (int j = 0; j < n3; j++) // iterating through columns & n3 becaz it has 3 columns
{
for (int k = 0; k < n2; k++)
{
ans[i][j] += m1[i][k] * m2[k][j]; // k--> 1st columns = 2nd matrix rows
}
}
}
for(int i=0; i<n1; i++)
{
for(int j=0 ;j<n3; j++)
{
cout << ans[i][j] << "the ans is\n ";
}
cout << "\n";
}
return 0;
}