Given a matrix, check whether it’s Magic Square or not. A Magic Square is a n x n matrix of distinct element from 1 to n2 where sum of any row, column or diagonal is always equal to same number.
Input : n = 3 2 7 6 9 5 1 4 3 8 Output : Magic matrix Explanation:In matrix sum of each row and each column and diagonals sum is same = 15. Input : n = 3 1 2 2 2 2 1 2 1 2 Output : Not a Magic Matrix Explanation:In matrix sum of each row and each column and diagonals sum is not same.
1. Find sum of prime diagonal and secondary diagonal.
2. Calculate sum of each rows and columns.
3. If the prime diagonal and secondary diagonal sums is equal to every row’s sum and every column’s sum, then it is magic matrix.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum cost to convert 3 X 3 matrix into magic square
- Minimum changes needed to make a 3*3 matrix magic square
- Magic Square
- Magic Square | Even Order
- Fill missing entries of a magic square
- Check whether a Matrix is a Latin Square or not
- Check if matrix can be converted to another matrix by transposing square sub-matrices
- Check if it is possible to make the given matrix increasing matrix or not
- Program to check if a matrix is Binary matrix or not
- Construct a square Matrix whose parity of diagonal sum is same as size of matrix
- Check if a given matrix can be converted to another given matrix by row and column exchanges
- Check if a matrix contains a square submatrix with 0 as boundary element
- Check if a given matrix is sparse or not
- Check if a given matrix is Hankel or not
- Check whether the given Matrix is balanced or not
- Check if the Matrix follows the given constraints or not
- Check whether a given matrix is orthogonal or not
- Count Magic squares in a grid
- Given an n x n square matrix, find sum of all sub-squares of size k x k
- Print maximum sum square sub-matrix of given size
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.