Computer Science, asked by shrutisri978, 1 year ago

Write an algorithm for multiplication of a lower triangular matrix with a upper triangular matrix.

Answers

Answered by topanswers
1

Algorithm:

  • Declare the matrix and get the input from the user.
  • For lower triangular matrix, the row and column is checked and if column position is greater than row position, that position is made 0.
  • For upper triangular matrix, the row and column is checked and if column position is lower than row position, that position is made 0.
  • The two matrices are multiplied.

Program:  

In C++,

#include<iostream>  

using namespace std;  

// 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;  

   }  

}  

// Upper triangular marix  

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;  

   }  

}  

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;  

}

Read more on Brainly.in - https://brainly.in/question/6433960

Similar questions