Skip to content

Commit

Permalink
Merge pull request #10 from Abhishek21sh/master
Browse files Browse the repository at this point in the history
Create Program to print Lower triangular and Upper triangular matrix …
  • Loading branch information
Upen001 authored Oct 24, 2021
2 parents 3d561fe + f77787b commit e7cb5d7
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// C++ program to print Lower
// triangular and Upper triangular
// matrix of an array
#include<iostream>

using namespace std;

// Function to form
// lower triangular matrix
void lower(int matrix[3][3], int row, int col)
{
int i, j;
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
if (i < j)
{
cout << "0" << " ";
}
else
cout << matrix[i][j] << " ";
}
cout << endl;
}
}

// Function to form upper triangular matrix
void upper(int matrix[3][3], int row, int col)
{
int i, j;

for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
if (i > j)
{
cout << "0" << " ";
}
else
cout << matrix[i][j] << " ";
}
cout << endl;
}
}

// Driver Code
int main()
{
int matrix[3][3] = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};
int row = 3, col = 3;

cout << "Lower triangular matrix: \n";
lower(matrix, row, col);

cout << "Upper triangular matrix: \n";
upper(matrix, row, col);

return 0;
}

0 comments on commit e7cb5d7

Please sign in to comment.