This is a Cpp program which display the upper triangular form of a given matrix. |
See the figure below,
![]() |
| Upper Triangular form of a given matrix |
#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 :
| Upper Triangular form of a given matrix |
