Question: C++ Exercise P6.18. Implement the following algorithm to construct magic n x n squares it works only if n is odd. Place a 1 in
Exercise P6.18. Implement the following algorithm to construct magic n x n squares it works only if n is odd. Place a 1 in the middle of the bottom row. After k has been placed in the (i, j) square, place k+1 into the square to the right and down, wrap- ping around the borders. However, if you reach a square that has already been filled, then you must move one square up instead. Here is the 5 5 square that you get if you follow this method: 11 18 25 2 9 10 12 19 21 3 4 6 13 20 22 23 5 7 1416 17 24 1, 8 15 Write a program whose input is the number n and whose output is the magic square of order n if n is odd
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
