Question: Write a program that reads in an odd integer N from user input and prints out an N x N magic square (i.e. matrix). The

Write a program that reads in an odd integer N from user input and prints out an NxN magic square (i.e. matrix). The square contains each of the integers between 1 and N^2 exactly once, such that all row sums, column sums, and diagonal sums are equal.

Sample Output #1:

2 7 6 9 5 1 4 3 8

Sample Output #2:

17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9

NOTE: Be sure to perform input validation for the value N.

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!