Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ : An n n matrix that is filled with the numbers 1, 2, 3, . . ., n^2 is a magic square if the

C++ : An n n matrix that is filled with the numbers 1, 2, 3, . . ., n^2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value.

In C++, write a program that reads in 16 values from the keyboard and tests whether they form a magic square when put into a 4 4 vector. You need to work on three tasks:

Process the input into the form of 2 dimensional vector form, i.e., You need to fill in the write vector to square function.

Print out the square. That is, you print 4 numbers in each line and use a space to separate them. The square should have 4 lines. You need to fill in the print square function.

When the numbers are put into a square, check whether the sums of the rows, columns, and diagonals equal to each other, i.e., You need to fill in the is magicsquare function. Hint If the matrix is magic square, then all of its row sums, column sums and diagonal sums should equal to (1 + 2 + + 15 + 16)/4 = 34.

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions