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
- Print matrix in diagonal pattern
- Zigzag (or diagonal) traversal of Matrix
- Squares of Matrix Diagonal Elements
- Reverse Diagonal elements of matrix
- Program to convert given Matrix to a Diagonal Matrix
- Program to convert the diagonal elements of the matrix to 0
- Print numbers in matrix diagonal pattern
- Ways of filling matrix such that product of all rows and all columns are equal to unity
- Minimum operations required to make each row and column of matrix equals
- Find number of transformation to make two Matrix Equal
- Minimum operations of given type to make all elements of a matrix equal
- Diagonal of a Regular Decagon
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.