forked from zapellass123/OpenEmailGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiplication_of_matrix.cpp
72 lines (59 loc) · 1.61 KB
/
multiplication_of_matrix.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
//multiplication of 2 matrix
#include<iostream>
using namespace std;
int main()
{
int mr1,mc1,mr2,mc2,m1[5][5],m2[5][5],result[5][5]={};
cout<<"\nEnter the no. row 1st matrix:";
cin>>mr1;
cout<<"Enter the no. of coloum 1st matrix:";
cin>>mc1;
cout<<"\nEnter the no. row 2nd matrix:";
cin>>mr2;
cout<<"Enter the no. coloum 2nd matrix:";
cin>>mc2;
cout<<"\nEnter the element of 1st matrix:";
for (int i = 1 ; i <= mr1 ; i++)
{
for (int j = 1 ; j <= mr1 ; j++)
{
cout<<"\nm1["<<i<<"]["<<j<<"]:";
cin>>m1[i][j];
}
}
cout<<"\nEnter the element of 2nd matrix:";
for (int i = 1 ; i <= mr2 ; i++)
{
for (int j = 1 ; j <= mr2 ; j++)
{
cout<<"\nm2["<<i<<"]["<<j<<"]:";
cin>>m2[i][j];
}
}
if (mc1 == mr2)
{
for (int i = 1 ; i <= mc1 ; i++)
{
for (int j = 1; j <= mr1; j++)
{
for (int k = 1; k <= mr1 ; k++)
{
result[i][j]=result[i][j]+m1[k][j]*m2[i][k];
}
}
}
}
else
{
cout<<"\nMultiplication cannot be performed!!!";
}
cout<<"Multiplication is:";
for (int i = 1; i <= mr1; i++)
{
for (int j = 1; j <= mr1; j++)
{
cout<<result[i][j]<<" ";
}
}
return 0;
}