-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmenuULT12Diag.cpp
More file actions
executable file
·115 lines (97 loc) · 1.65 KB
/
Copy pathmenuULT12Diag.cpp
File metadata and controls
executable file
·115 lines (97 loc) · 1.65 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int A[10][10], r_1, c_1, choice, choice_2;
cout << "Enter number of rows: ";
cin >> r_1;
cout << "Enter number of columns: ";
cin >> c_1;
cout << "Enter the matrix, row wise\n";
for(int r = 0; r < r_1; r++)
{
for(int c = 0; c < c_1; c++)
{
cout << "Enter value for " << r << ", " << c << ": ";
cin >> A[r][c];
}
}
cout << "Entered matrix is \n";
for(int r = 0; r < r_1; r++)
{
cout << "\n";
for(int c = 0; c < c_1; c++)
{
cout << A[r][c] << " ";
}
}
do
{
cout << "\n1. Primary diagonal.\n2. Secondary diagonal.\n3. Display upper triangle.\n4. Display lower triangle.";
cout << "\nChoice: ";
cin >> choice;
if(choice == 1)
{
for(int r = 0; r < r_1; r++)
{
for(int c = 0; c < c_1; c++)
{
if(r == c)
{
cout << A[r][c] << endl;
}
}
}
}
else if(choice == 2)
{
for(int r = 0; r < r_1; r++)
{
for(int c = 0; c < c_1; c++)
{
if(r + c == r_1 - 1)
{
cout << A[r][c] << endl;
}
}
}
}
else if (choice == 3)
for(int r = 0; r < r_1; r++)
{
cout << endl;
for(int c = 0; c < c_1; c++)
{
if(r <= c)
{
cout << A[r][c];
}
else
{
cout << " ";
}
}
}
else if (choice == 4)
for(int r = 0; r < r_1; r++)
{
cout << endl;
for(int c = 0; c < c_1; c++)
{
if(r + c <= r_1 - 1)
{
cout << A[r][c];
}
else
{
cout << " ";
}
}
} cout << "\n";
cout << "Do you wanna continue? (y/n): ";
cin >> choice_2;
}
while (choice_2 == 'y');
return 0;
}