정사각 행렬 M[r][c]가 주어지면 'r'은 몇 개의 행이고 'c'는 r =c인 열이므로 'M'이 하삼각 행렬인지 확인해야 합니다.
하삼각 행렬 -
하삼각행렬은 주대각선(주대각선 포함) 아래의 요소가 0이 아니고 위의 요소가 0인 행렬입니다.
아래 주어진 예에서와 같이 -

위 그림에서 빨간색으로 강조 표시된 요소는 0이고 나머지 요소는 0이 아닌 주 대각선의 위쪽 요소입니다.
예시
Input: m[3][3] = { {1, 0, 0},
{2, 3, 0},
{4, 5, 6}}
Output: yes
Input: m[3][3] == { {3, 0, 1},
{6, 2, 0},
{7, 5, 3} }
Output: no 알고리즘
Start
Step 1 -> define macro as #define size 4
Step 2 -> declare function to check matrix is lower triangular matrix
bool check(int arr[size][size])
Loop For int i = 0 and i < size and i++
Loop For int j = i + 1 and j < size and j++
If (arr[i][j] != 0)
return false
End
End
End
return true
step 3 -> In main()
Declare array int arr[size][size] = { { 1, 0, 0, 0 },
{ 2, 3, 0, 0 },
{ 4, 5, 6, 0 },
{ 7, 8, 9, 10 } }
If (check(arr))
Print its a lower triangular matrix
Else
Print its not a lower triangular matrix
Stop 예시
#include <bits/stdc++.h>
#define size 4
using namespace std;
// check matrix is lower triangular matrix
bool check(int arr[size][size]){
for (int i = 0; i < size; i++)
for (int j = i + 1; j < size; j++)
if (arr[i][j] != 0)
return false;
return true;
}
int main(){
int arr[size][size] = { { 1, 0, 0, 0 },
{ 2, 3, 0, 0 },
{ 4, 5, 6, 0 },
{ 7, 8, 9, 10 } };
if (check(arr))
cout << "its a lower triangular matrix";
else
cout << "its not a lower triangular matrix";
return 0;
} 출력
its a lower triangular matrix