-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix Addition.cpp
More file actions
56 lines (56 loc) · 1.27 KB
/
Copy pathMatrix Addition.cpp
File metadata and controls
56 lines (56 loc) · 1.27 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
#include<iostream>
using namespace std;
//Easy C++_Code: Ajmal Hussain
int main(){
int r,c,i,j;
cout<<"Enter no. of rows: ";
cin>>r;
cout<<"Enter no. of columns: ";
cin>>c;
int a[r][c],b[r][c],sum[r][c];
cout<<endl<<"Enter elements of 1st Matrix:"<<endl;
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cout<<"Matrix["<<i<<"]["<<j<<"]: ";
cin>>a[i][j];
}
}
//Learnig never ends_Ajmal Hussain
cout<<endl<<"Enter elements of 2nd Matrix:"<<endl;
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cout<<"Matrix["<<i<<"]["<<j<<"]: ";
cin>>b[i][j];
}
}
//sum
for(i=0; i<r; i++){
for(j=0; j<c; j++){
sum[i][j]=a[i][j]+b[i][j];
}
}
cout<<"1st Matrix:"<<endl;
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cout<<a[i][j]<<"\t";
}
cout<<endl;
}
cout<<"2nd Matrix:"<<endl;
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cout<<b[i][j]<<"\t";
}
cout<<endl;
}
cout<<"Sum of 1st and 2nd Matrix:"<<endl;
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cout<<sum[i][j]<<"\t";
}
cout<<endl;
}
//Thank You!
//By: Md Ajmal Hussain
return 0;
}