-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadditiom-of-two-matrices
70 lines (57 loc) · 1.54 KB
/
additiom-of-two-matrices
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
63
64
65
66
67
68
69
#include<iostream>
using namespace std;
int main()
{
int r,c,a[100][100],b[100][100],sum[100][100],i,j;
cout<<"Enter number of rows between (1-100): ";
cin>> r;
cout<<"Enter number of coloums between (1-100): ";
cin>> c;
cout<<endl<<"Enter elements of 1st matrix: "<<endl;
//storing elements of first maitrix
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
cout<<"Enter element a"<<i+1<<j+1<<": " ;
cin>>a[i][j];
}
cout<<endl<<"Enter elements of 2nd matrix: "<<endl;
//storing elements of second matrix
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
cout<<"Enter element b"<<i+1<<j+1<<": ";
cin>>b[i][j];
}
//ADDING TWO MATRICES
for(i=0;i<r;i++)
for(j=0;j<c;j++)
sum[i][j] = a[i][j] + b[i][j];
//Displaying the sum of two matrix
cout<<endl<<"sum of two matrix is: "<<endl;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
cout<<sum[i][j]<<" ";
if(j==c-1)
cout<< endl;
}
return 0;
}
/* OUTPUT OF PROGRAM
Enter number of rows between (1-100): 2
Enter number of coloums between (1-100): 2
Enter elements of 1st matrix:
Enter element a11: 2
Enter element a12: 3
Enter element a21: 7
Enter element a22: 5
Enter elements of 2nd matrix:
Enter element b11: 7
Enter element b12: 5
Enter element b21: 0
Enter element b22: 1
sum of two matrix is:
9 8
7 6
*/