Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write in c++ plz. as simple as you can. 15. (Computation) A magic square is a square of numbers with N rows and N columns,

image text in transcribed

image text in transcribed

write in c++ plz. as simple as you can.

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

Understand how HRM can support a sustainable competitive advantage.

Answered: 1 week ago

Question

Develop knowledge of the Italian entrepreneurial business context.

Answered: 1 week ago