Thursday, 12 March 2015

Cpp Program to display Lower Triangular form of a matrix



This is a Cpp program which display the lower triangular form of a given matrix.

To display the lowe triangular form of a given matrix we make all the elements above the diagonal row as zero.





See the figure below,
Lower triangular form of a matrix





Download Code
PROGRAM :
#include <iostream>

using namespace std;

int main()
{
    int rows,columns,i,j;
    cout << "Enter order of matrix  \t:";
    cin >> rows;
    cin >> columns;
    int matrix[rows][columns];
    cout << "\n\nEnter elements of a matrix\n";
    for(i=0; i<rows; i++)
    {
        for(j=0; j<columns; j++)
        {
            cout << "Enter element m" << i+1 << j+1 << ": \t";
            cin >> matrix[i][j];
        }
    }
    cout << "\n\nMATRIX is :\n";
    for(i=0; i<rows; i++)
    {
        for(j=0; j<columns; j++)
        {
            cout << matrix[i][j] << "\t";
        }
        cout << endl;
    }
    cout << "\n\nIts Upper Triangular form is: \n";
    for(i=0; i<rows; i++)
    {
        for(j=0; j<columns; j++)
        {
            if(i<=j)
                cout << matrix[i][j] << "\t";
            else
                cout << 0 << "\t";
        }
        cout << endl;
    }
    return 0;
}


OUTPUT : 
Lower Triangular form of a matrix




Download Code