Two-Dimensional Arrays
Consider a 2D matrix of size n×m
. Where n
is the number of rows (maximum 10) and m
is the number of columns (maximum 10). Write a C++ program to check if the given matrix is:
Upper triangle (U).
Lower triangle (L).
Zero (Z).
Non-triangle (N).
I/O
Program Input:
The size of matrix: n
and m
.
Matrix elements.
Program Output:
A single character from the following list: {U,L,Z,N}
.
Tip(s)
Enter the first row, element by element separated by a space. After you reach the last element in the row, press "Enter" to start on a new line. Then enter the elements of the second row and so on so forth until you enter all matrix elements. This allows you to visualise the matrix on your terminal.
Sample Testcase 0:
Input:
5 5
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
1 1 1 1 1
Output:
U
Sample Testcase 1:
Input:
3 3
1 1 1
0 1 1
0 0 1
Output:
L
Sample Testcase 2:
Input:
2 3
Output:
N