-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2D_MAT_A.CPP
More file actions
35 lines (35 loc) · 767 Bytes
/
2D_MAT_A.CPP
File metadata and controls
35 lines (35 loc) · 767 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
//Matrix addition
#include<iostream.h>
#include<conio.h>
void main()
{int m,n,p,q,a[10][10],b[10][10],c[10][10];
clrscr();
cout<<"Enter the dimension for the first matrix ";
cin>>m>>n;
cout<<"Enter the dimension for the second matrix ";
cin>>p>>q;
cout<<"Enter the elements of first matrix ";
for(int i=0;i<m;i++)
{ for(int j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"Enter the elements of the second matrix ";
for(i=0;i<p;i++)
{ for(int j=0;j<q;j++)
cin>>b[i][j];
}
if(m==p&&n==q)
{ for(i=0;i<m;i++)
{ for(int j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
}
}
else
cout<<"Addition not possible "<<endl;
cout<<"The sum of the matrices is "<<endl;
for(i=0;i<m;i++)
{ for(int j=0;j<n;j++)
cout<<"\t"<<c[i][j]<<endl;
}
getch();
}