-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadditionoftwomatrices.cpp
More file actions
59 lines (48 loc) · 904 Bytes
/
additionoftwomatrices.cpp
File metadata and controls
59 lines (48 loc) · 904 Bytes
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
//addition of two matrices
#include<iostream>
using namespace std;
int main(){
int r, c, i, j;
cout<<"enter the number of rows: ";
cin>>r;
cout<<"enter the number of columns: ";
cin>>c;
int m1[r][c], m2[r][c], sum[r][c];
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cout<<"enter element of m1 matrix: ";
cin>>m1[i][j];
}
cout<<endl;
}
cout<<"first matrix is:\n";
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cout<<m1[i][j]<<"\t";
}
cout<<endl;
}
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cout<<"enter element of m2 matrix: ";
cin>>m2[i][j];
}
cout<<endl;
}
cout<<"second matrix is:\n";
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cout<<m2[i][j]<<"\t";
}
cout<<endl;
}
cout<<"sum of the two matrices is:\n";
for(i=0; i<r; i++){
for(j=0; j<c; j++){
sum[i][j]=m1[i][j]+m2[i][j];
cout<<sum[i][j]<<"\t";
}
cout<<endl;
}
return 0;
}