C++
- voluntas
- @ignis_fatuus
- ブン
- @Linda_pp
- 清楚なC++メイドBOT
- @tzik_tack
- 長谷川一輝
- wraith13
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- Siv3D
- takezoh
- まろ
- @okdshin
- @hnokx
- @ishidakei
- @take_cheeze
- TAKEI Yuya
- @mumumu
- I (@wx257osn2)
- Tommy6
- @tyottyoworks
- ___shanon
- わたやん
- @KorekaraSEDB
- @kariya_mitsuru
- @ciniml
- @beam2d
- @grafi_tt
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
36
1
2
using namespace std;
3
int main ()
4
{
5
int m, n, p, q, i, j, A[5][5], B[5][5]; //Program to add 2 matrices using multi-dimensional arrays
6
cout << "Enter rows and column of matrix A : ";
7
cin >> m >> n;
8
cout << "Enter rows and column of matrix B : ";
9
cin >> p >> q;
10
if ((m != p) || (n != q))
11
{
12
cout << "Matrices cannot be added!";
13
exit(0);
14
}
15
cout << "Enter elements of matrix A : ";
16
17
for (i = 0; i < m; i++)
18
for (j = 0; j < n; j++)
19
cin >> A[i][j];
20
cout << "Enter elements of matrix B : ";
21
22
for (i = 0; i < p; i++)
23
for (j = 0; j < q; j++)
24
cin >> B[i][j];
25
26
cout << "Sum of matrices\n";
27
28
for (i = 0; i < m; i++)
29
{ for (j = 0; j < n; j++)
30
cout << A[i][j] + B[i][j] << " ";
31
cout << "\n";
32
}
33
34
return 0;
35
}
36
$ g++ prog.cc -Wall -Wextra -I/opt/wandbox/boost-1.73.0/gcc-10.1.0/include -std=c++11 -pedantic
Stdin
2 2
2 2
1 2
3 4
5 6
7 8
Start
Enter rows and column of matrix A : Enter rows and column of matrix B : Enter elements of matrix A : Enter elements of matrix B : Sum of matrices 6 8 10 12
0
Finish