Magic Square Generator

Enter the desired Magic Constant and the Order (n) of the square. A magic square is an (n x n) matrix of distinct positive integers where the sum of numbers in every row, every column, and both main diagonals is equal to the Magic Constant.

To achieve a given magic constant using integers in a magic square, it’s essential to consider the natural magic constant associated with the square's order. For example, the natural magic constant of a magic square of order 6 is 111. If the given magic constant differs from the natural one, then the difference must be divisible by 6 (i.e., by the order of the square). This ensures that the difference can be evenly distributed across the entire square without resulting in fractions or non-integer values. To calculate the natural magic constant (magic sum) of a magic square of order n: Use the following formula: M=[n*((n*n)+1)]/2

Where:
M is the natural magic constant.
n is the order of the magic square (i.e., the number of rows or columns).
A natural magic square means it contains all integers from 1 to (n x n) exactly once, without repetition.

References: