Given a square matrix, swap the element of major and minor diagonals.
Major Diagonal Elements of a Matrix :
The Major Diagonal Elements are the ones that occur from Top Left of Matrix Down To Bottom Right Corner. The Major Diagonal is also known as Main Diagonal or Primary Diagonal.
Minor Diagonal Elements of a Matrix :
The Minor Diagonal Elements are the ones that occur from Top Right of Matrix Down To Bottom Left Corner. Also known as Secondary Diagonal.
Input : 0 1 2 3 4 5 6 7 8 Output : 2 1 0 3 4 5 8 7 6
The Simple thing one should know is that the indexes of Primary or Major diagonal are same i.e. lets say A is matrix then A will be a Major Diagonal element and sum of indexes of Minor Diagonal is equal to size of Matrix. Lets say A is a matrix of size 3 then A will be Minor Diagonal element.
Below is the implementation of above approach :
2 1 0 3 4 5 8 7 6
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
- Sum of all parts of a square Matrix divided by its diagonals
- Find the product of sum of two diagonals of a square Matrix
- Sum of both diagonals of a spiral odd-order square matrix
- Finding the converging element of the diagonals in a square matrix
- Return an array of anti-diagonals of given N*N square matrix
- Row-wise common elements in two diagonals of a square matrix
- Find smallest and largest element from square matrix diagonals
- Sort the major diagonal of the matrix
- Performance analysis of Row major and Column major order of storing arrays in C
- Number of positions with Same address in row major and column major order
- Check if row-major order path of Matrix is palindrome or not
- Search in a sorted 2D matrix (Stored in row major order)
- Program to print the Diagonals of a Matrix
- Program to Interchange Diagonals of Matrix
- Program to print the Diagonals of a Matrix in O(N) time
- Efficiently compute sums of diagonals of a matrix
- Number of cells in the right and left diagonals passing through (x, y) in a matrix
- Center element of matrix equals sums of half diagonals
- Check if matrix can be converted to another matrix by transposing square sub-matrices
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar