Given 9 elements in a 3 x 3 matrix where the value of diagonals are 0. We need to find the values in diagonal to make the sum of every row, column and diagonal equal.
Input: 0 3 6 5 0 5 4 7 0 Output: 6 3 6 5 5 5 4 7 4 Explanation: Now the value of the sum of any row or column is 15 Input: 0 4 4 4 0 4 4 4 0 Output: 4 4 4 4 4 4 4 4 4
- Let’s say the diagonal is x, y and z.
- The value of x will be ( x2, 3 + x3, 2 ) / 2.
- The value of z will be ( x1, 2 + x2, 1 ) / 2.
- The value of y will be ( x + z ) / 2.
Below is the implementation of the above approach:
Matrix initially: 0 54 48 36 0 78 66 60 0 Matrix with diagonals: 69 54 48 36 34 78 66 60 45
- Program to swap upper diagonal elements with lower diagonal elements of matrix.
- Program to check diagonal matrix and scalar matrix
- Mirror of matrix across diagonal
- Reverse Diagonal elements of matrix
- Squares of Matrix Diagonal Elements
- Print matrix in diagonal pattern
- Zigzag (or diagonal) traversal of Matrix
- Program to convert given Matrix to a Diagonal Matrix
- Print all the sub diagonal elements of the given square matrix
- Program to convert the diagonal elements of the matrix to 0
- Print numbers in matrix diagonal pattern
- Find the sum of the diagonal elements of the given N X N spiral matrix
- Print all the super diagonal elements of the given square matrix
- Find a Symmetric matrix of order N that contain integers from 0 to N-1 and main diagonal should contain only 0's
- Ways of filling matrix such that product of all rows and all columns are equal to unity
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.