-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintUpperLowerTriangleOfSquareMatrix.cpp
More file actions
48 lines (41 loc) · 1.03 KB
/
PrintUpperLowerTriangleOfSquareMatrix.cpp
File metadata and controls
48 lines (41 loc) · 1.03 KB
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
// Displays the upper and lower triangle of a square matrix.
//
// Complier: Visual Studio 2013 (v120)
#include <iostream>
#include <array>
#include <string>
using namespace std;
int main()
{
array<array<int, 5>, 5> matrix { {
{ { 1, 2, 3, 4, 5 } },
{ { 1, 2, 3, 4, 5 } },
{ { 1, 2, 3, 4, 5 } },
{ { 1, 2, 3, 4, 5 } },
{ { 1, 2, 3, 4, 5 } },
} };
cout << endl << "Matrix" << endl;
for (const auto &i : matrix) {
for (const auto &j : i) {
cout << j;
}
cout << endl;
}
cout << endl << "Top Triangle" << endl;
for (auto i = 0; i < matrix.size(); ++i) {
for (auto j = 0; j < matrix[i].size(); ++j) {
cout << ((i < j) ? to_string(matrix[i][j]) : string("X"));
}
cout << endl;
}
cout << endl << "Bottom Triangle" << endl;
for (auto i = 0; i < matrix.size(); ++i) {
for (auto j = 0; j < matrix[i].size(); ++j) {
cout << ((i > j) ? to_string(matrix[i][j]) : string("X"));
}
cout << endl;
}
cout << "[Press enter to exit]" << endl;
cin.ignore();
return 0;
}