Answer to Question #236042 in C for xyz

Question #236042
Design an algorithm to convert a lower triangular matrix to upper triangular matrix.
1
Expert's answer
2021-09-11T23:40:18-0400
#include<stdio.h> 


int main() 
{ 
   int i, j;
    int row,column;
    printf("Enter rows\n");
    scanf("%d", &row);
    
    printf("Enter columns\n");
    scanf("%d", &column);
    
    
  int matrix[row][column];
  printf("\nEnter the elements of the matrix:\n");
  for(i=0;i<row;i++)
  {
    for(j=0;j<column;j++)
    {
      scanf("%d", &matrix[i][j]);
	  
    }
  }
 printf("\n");
  
  printf("Lower triangular matrix: \n") ; 
  for (i = 0; i < row; i++) 
  { 
    for (j = 0; j < column; j++) 
    { 
      if (i < j) 
      { 
       printf("0  "); 
      } 
      else
      printf("%d  ", matrix[i][j]);
      
    } 
    printf("\n"); 
  } 
  
  
  printf("Upper triangular matrix: \n");
  for (i = 0; i < row; i++) 
  { 
    for (j = 0; j < column; j++) 
    { 
      if (i > j) 
      { 
        printf("0  "); 
		
      } 
      else
      printf("%d  ", matrix[i][j]);
    } 
    printf("\n"); 
  }  
  return 0; 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS