Magic Squares
* To make a magic Grid/square just folow the 5 points that is given below.
* n=row=column;
* The Addition will follow the equation n*(n^2+1)/2
(1) First we have to store 1 in (n/2,n-1) position then keep storing 2,3,4,5..<n^2 by following points.
(2)Function(i,j) = (i-1,j+1);
(3)If (i = -1) then we have to make it as (i=n-1);
(4)If (j=n) then we have to make it as j=0;
(5)If (i,j) = (-1,n) then we will convert it as (0,n-2);
(6)If the position is already occupied by value then we will make it as( i=i+1) & (j=j-2);
Example:
2 7 6
9 5 1
4 3 8
* n=row=column;
* The Addition will follow the equation n*(n^2+1)/2
(1) First we have to store 1 in (n/2,n-1) position then keep storing 2,3,4,5..<n^2 by following points.
(2)Function(i,j) = (i-1,j+1);
(3)If (i = -1) then we have to make it as (i=n-1);
(4)If (j=n) then we have to make it as j=0;
(5)If (i,j) = (-1,n) then we will convert it as (0,n-2);
(6)If the position is already occupied by value then we will make it as( i=i+1) & (j=j-2);
Example:
2 7 6
9 5 1
4 3 8
Comments
Post a Comment