forked from thelokeshgoel00/Competitive_Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix_multiplication.cpp
More file actions
62 lines (59 loc) · 1.35 KB
/
Copy pathMatrix_multiplication.cpp
File metadata and controls
62 lines (59 loc) · 1.35 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
//Matrix Multiplication
#include<iostream>
using namespace std;
int main()
{
int n,m,i,j,k,sum=0;
cout<<"Enter the number of rows and columns in matrix 1: ";
cin>>n>>m;
int a,b;
cout<<"Enter the number of rows and columns in matrix 2: ";
cin>>a>>b;
int m1[n][m],m2[a][b],m3[n][b];
if(m!=a)
{
cout<<"We cannot multiply these two matrices"<<endl;
}
else{
cout<<"Enter elements of matrix 1: "<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>m1[i][j];
}
}
cout<<"Enter the elements of matrix 2 : "<<endl;
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
cin>>m2[i][j];
}
}
for(i = 0; i < n; ++i){
for(j = 0; j < b; ++j)
{
m3[i][j]=0;
}}
for(i=0;i<n;i++)
{
for(j=0;j<b;j++)
{
sum=0;
for(k=0;k<n;k++)
{
m3[i][j]+=m1[i][k]*m2[k][j];
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<b;j++)
{
cout<<m3[i][j]<<" ";
}
cout<<endl;
}
}
}