-
Notifications
You must be signed in to change notification settings - Fork 0
/
sum_mat.cpp
73 lines (59 loc) · 998 Bytes
/
sum_mat.cpp
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
70
71
72
73
/* exp8_2:Sum of two matrix*/
# include <iostream>
using namespace std;
int main()
{
int x,y,i,j;
cout<<"rows-";
cin>>x;
cout<<"column-";
cin>>y;
int mat1[x][y];
int mat2[x][y];
for ( i=0;i<x;i++)
{
for ( j=0;j<y;j++)
{
cout<<"\ns["<<i<<"]["<<j<<"]= ";
cin>>mat1[i][j];
}
}
for ( i=0;i<x;i++)
{
for ( j=0;j<y;j++)
{
cout<<"\ns1["<<i<<"]["<<j<<"]= ";
cin>>mat2[i][j];
}
}
int sum[i][j];
for ( i=0;i<x;i++)
{
for ( j=0;j<y;j++)
{
sum[i][j]=mat1[i][j]+mat2[i][j];
}
}
for ( i=0;i<x;i++)
{
for ( j=0;j<y;j++)
{
cout<<sum[i][j];
cout<<" ";
}
cout<<endl;
}
}
/*output
rows-2
column-2
s[0][0]= 2
s[0][1]= 6
s[1][0]= 4
s[1][1]= 3
s1[0][0]= 8
s1[0][1]= 0
s1[1][0]= 5
s1[1][1]= 7
10 6
9 10*/