Skip to content
Related Articles

Related Articles

JavaScript Program to check if matrix is lower triangular

Improve Article
Save Article
Like Article
  • Last Updated : 17 Jan, 2022

Given a square matrix and the task is to check the matrix is in lower triangular form or not. A square matrix is called lower triangular if all the entries above the main diagonal are zero. 
 

Examples: 
 

Input : mat[4][4] = {{1, 0, 0, 0},
                     {1, 4, 0, 0},
                     {4, 6, 2, 0},
                     {0, 4, 7, 6}};
Output : Matrix is in lower triangular form.

Input : mat[4][4] = {{1, 0, 0, 0},
                     {4, 3, 0, 1},
                     {7, 9, 2, 0},
                     {8, 5, 3, 6}};
Output : Matrix is not in lower triangular form.

 

Javascript




<script>
// Java  script Program to check for
// a lower triangular matrix.
  
    let N = 4;
  
    // Function to check matrix is
    // in lower triangular form or not.
    function isLowerTriangularMatrix(mat)
    {
        for (let i = 0; i < N; i++)
            for (let j = i + 1; j < N; j++)
                if (mat[i][j] != 0)
                    return false;
  
        return true;
    }
  
    // Driver function.
      
          
        let mat = [[ 1, 0, 0, 0 ],
                        [ 1, 4, 0, 0 ],
                        [ 4, 6, 2, 0 ],
                        [ 0, 4, 7, 6 ]];
                          
        // Function call
        if (isLowerTriangularMatrix(mat))
            document.write("Yes");
        else
            document.write("No");
  
          
// contributed by sravan kumar
</script>

Output: 
 

Yes

Please refer complete article on Program to check if matrix is lower triangular for more details!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!