Question
In C++, write a program that queries the user for an odd integer n, where the permissible values for n are 3, 5, or 7.
In C++, write a program that queries the user for an odd integer n, where the permissible values for n are 3, 5, or 7. Create a 7x7 static matrix and use it to display an n by n magic square. Your solution for the 5x5 magic square must be this:
A magic square is an n X n matrix in which each of the integers 1,2,3, ..., nZ appears exactly once and all column sums, row sums, and diagonal sums are equal and add up to 65. The size of the matrix in all of the functions must be fixed at compile time.
The following is a procedure for constructing an n x n magic square for any odd integer n. Place 1 in the middle of the top row. Then, after integer k has been placed, move up one row and one column to the right to place the next integer k + 1, unless one of the following occurs:
If a move takes you above the top row in the jth column, move to the bottom of the jth column and place k + 1 there.
If a move takes you outside to the right of the square in the ith roW, place k + 1 in the ith row at the left side.
If a move takes you to an already filled square or if you move out of the square at the upper right-hand corner, place k + 1 immediately below k.
Original responses please for upvote
\begin{tabular}{|c|c|c|c|c|} \hline 17 & 24 & 1 & 8 & 15 \\ \hline 23 & 5 & 7 & 14 & 16 \\ \hline 4 & 6 & 13 & 20 & 22 \\ \hline 10 & 12 & 19 & 21 & 3 \\ \hline 11 & 18 & 25 & 2 & 9 \\ \hline \end{tabular}Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started