VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-swap-upper-diagonal-elements-lower-diagonal-elements-matrix/

⇱ Program to swap upper diagonal elements with lower diagonal elements of matrix. - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to swap upper diagonal elements with lower diagonal elements of matrix.

Last Updated : 25 Jul, 2022

Given a square matrix, swap upper diagonal elements of matrix with lower diagonal elements of matrix.

Examples : 

Input: 2 3 5 6
 4 5 7 9
 8 6 4 9
 1 3 5 6

Output: 2 4 8 1
 3 5 6 3
 5 7 4 5
 6 9 9 6

Input: 1 2 3 
 4 5 6
 7 8 9

Output: 1 4 7
 2 5 8
 3 6 9
Recommended Practice

Below is the implementation of above idea : 


Output
2 4 8 1 
3 5 6 3 
5 7 4 5 
6 9 9 6 

Time Complexity: O(N2)
Auxiliary Space: O(1) 

Comment
Article Tags:
Article Tags: