forked from sahilbansal17/Cplusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathADD_MATRIX.txt
More file actions
49 lines (47 loc) · 1.06 KB
/
ADD_MATRIX.txt
File metadata and controls
49 lines (47 loc) · 1.06 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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n1,m1,n2,m2;
cout<<"Enter row size of matrix 1 :";
cin>>n1;
cout<<"Enter col size of matrix 1 :";
cin>>m1;
cout<<"Enter row size of matrix 2 :";
cin>>n2;
cout<<"Enter col size of matrix 2 :";
cin>>m2;
if(n1!=n2 || m1!=m2)
{
cout<<"Addition not possible"<<endl;
return 0;
}
else
{
int a[n1][m1],b[n1][m1],c[n1][m1];
cout<<"Enter matrix 1 :"<<endl;
for(int i=0;i<n1;i++)
{
for(int j=0;j<m1;j++)
cin>>a[i][j];
}
cout<<"Enter matrix 2 :"<<endl;
for(int i=0;i<n1;i++)
{
for(int j=0;j<m1;j++)
cin>>b[i][j];
}
for(int i=0;i<n1;i++)
{
for(int j=0;j<m1;j++)
c[i][j]=a[i][j]+b[i][j];
}
cout<<"Addition matrix :"<<endl;
for(int i=0;i<n1;i++)
{
for(int j=0;j<m1;j++)
cout<<c[i][j]<<" ";
cout<<endl;
}
}
}