Question: write in c++ 15. (Computation) A magic square is a square of numbers with N rows and N columns, in which each integer value from

 write in c++ 15. (Computation) A magic square is a square

of numbers with N rows and N columns, in which each integer

write in c++

15. (Computation) A magic square is a square of numbers with N rows and N columns, in which each integer value from 1 to (N * N) appears exactly once, and the sum of each column, each row, and each diagonal is the same value. For example, Figure 7.21 shows a magic square in which N = 3, and the sum of the rows, columns, and diagonals is 15. Write a program that constructs and displays a magic square for a given odd number N. This is the algorithm: Insert the value 1 in the middle of the first row (element (0][N % 2]) After a value, x, has been placed, move up one row and to the right one column Place the next number, x + 1, there unless: (1) You move off the top (row = -1) in any column. Then move to the bottom row and place the next number, x + 1, in the bottom row of that column. (2) You move off the right end (column = N) of a row. Then place the next number, x + 1, in the first column of that row. (3) You move to a position that's already filled or out of the upper-right corner. Then place the next number, x + 1, immediately below x. Stop when you have placed as many elements as there are in the array ed Column 0 1 2 Row 081 6. 1 3 5 7 Figure 7.21 A magic square

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!