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
- Squares of Matrix Diagonal Elements
- Zigzag (or diagonal) traversal of Matrix
- Sum of non-diagonal parts of a square Matrix
- Print matrix in diagonal pattern
- Reverse Diagonal elements of matrix
- Program to convert given Matrix to a Diagonal Matrix
- Print numbers in matrix diagonal pattern
- Program to convert the diagonal elements of the matrix to 0
- Print all the sub diagonal elements of the given square matrix
- 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
- Program to find the Product of diagonal elements of a matrix
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.