computeMagicSquare

The creation of a magic square involves using the following algorithm. It will be your assignment to translate this algorithm into a program.

[1] Start number 1 in the top row, middle column.

[2] Place consecutive integers in a diagonally-up-to-the-right pattern.

[3] Any number that goes outside the matrix above row 1 is moved to the bottom row.

[4] Any number that goes outside the matrix past the right column is moved to the left column.

[5] Any number, which follows the multiple of the matrix size, is moved down 1 row.

Complete the 
computeMagicSquare method which generates a magic square matrix based on the given algorithm. Note that even though there's more than one way to generate these magic squares, you are being asked to generate the set using the algorithm shown. Below are examples of magic squares produced by the algorithm.
  



Type your solution        
Skills Practiced:
3.C
3.E
4.A
4.B
Copyright © StudyCS 2024 All rights reserved.