Answer to Question #236009 in C for xyz

Question #236009

Design an algorithm to convert a lower triangular matrix to upper triangular matrix.


1
Expert's answer
2021-09-11T23:40:13-0400
#include<stdio.h> 


int main() 
{ 
   int x, y;
    int r,c;
    printf("Enter rows\n");
    scanf("%d", &r);
    
    printf("Enter columns\n");
    scanf("%d", &c);
    
    
  int mat[r][c];
  printf("\nEnter matrix items:\n");
  for(x=0;x<r;x++)
  {
    for(y=0;y<c;y++)
    {
      scanf("%d", &mat[x][y]);
	  
    }
  }
 printf("\n");
  
  printf("Lower triangular matrix: \n") ; 
  for (x= 0; x < r; x++) 
  { 
    for (y= 0; y < c; y++) 
    { 
      if (x < y) 
      { 
       printf("0\t"); 
      } 
      else
      printf("%d\t", mat[x][y]);
      
    } 
    printf("\n"); 
  } 
  
  
  printf("Upper triangular matrix: \n");
  for (x = 0; x < r; x++) 
  { 
    for (y = 0; y < c; y++) 
    { 
      if (x > y) 
      { 
        printf("0\t"); 
		
      } 
      else
      printf("%d\t", mat[x][y]);
    } 
    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