-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab-5.2.cpp
44 lines (35 loc) · 1.01 KB
/
Lab-5.2.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
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand(static_cast<unsigned int>(time(0)));
int B[5][5];
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j) {
B[i][j] = rand() % 51 - 25;
}
}
int sumDiagonal = 0;
int sumBelowDiagonal = 0;
for (int i = 0; i < 5; ++i) {
for (int j = 0; j <= i; ++j) {
if (i == j) {
sumDiagonal += B[i][j];
} else {
sumBelowDiagonal += B[i][j];
}
}
}
cout << "Массив B" << endl;
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j) {
cout << setw(4) << B[i][j];
}
cout << endl;
}
cout << "Сумма элементов на главной диагонали: " << sumDiagonal << endl;
cout << "Сумма элементов под главной диагональю: " << sumBelowDiagonal << endl;
return 0;
}