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
- Reverse Diagonal elements of matrix
- Zigzag (or diagonal) traversal of Matrix
- Print matrix in diagonal pattern
- Program to convert given Matrix to a Diagonal Matrix
- Program to convert the diagonal elements of the matrix to 0
- Find the sum of the diagonal elements of the given N X N spiral matrix
- Print numbers in matrix diagonal pattern
- 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
- Minimum operations required to make each row and column of matrix equals
- Find number of transformation to make two Matrix Equal
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.