Question: Lo Shu Magic Square Write a program to determine if a gird follows the rules to be classified as a Lo Shu Magic Square. The

Lo Shu Magic Square

Write a program to determine if a gird follows the rules to be classified as a Lo Shu Magic Square. The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown in figure below. The Lo Shu Magic Square has the following properties:

The grid contains the numbers 1 through 9 exactly.

The sum of each row, each column, and each diagonal all add up to the same number. This is shown in figure below.

In a program, you can simulate a magic square using a two-dimensional array. Write a function that accepts a two-dimensional array as an argument, and determines whether the array is a Lo Shu Magic Square. Test the function in a program.

Note: Your program MUST include the following two functions and use them appropriately. You should also define constants for the number of rows and columns and use them throughout the program. The main procedural code should do little more than call the various functions as needed. You need to create at least two arrays, initialized with a valid magic square and one that is not (see below). You do not have to let them be inputted by hand each time the program runs--it is acceptable to just hard-code the values for this assignment.

// The following function test all rules and returns true only // if it succeeds in each! bool isMagicSquare(int values[][COLS]); // This function format it nicely. void showArray(int values[][COLS]); int main() { // Create a magic two-dimensional array. int magicArray[ROWS][COLS] = { { 4, 9, 2 }, { 3, 5, 7 }, { 8, 1, 6 } }; // Create a normal two-dimensional array. int normalArray[ROWS][COLS] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; // Create a normal two-dimensional array. int otherArray[ROWS][COLS] = { { 7, 7, 7 }, { 7, 7, 7 }, { 7, 7, 7 } }; The output should look something like this: 1 2 3 4 5 6 7 8 9 This is not a Lo Shu magic square. 4 9 2 3 5 7 8 1 6 This is a Lo Shu magic square. 7 7 7 7 7 7 7 7 7 This is not a Lo Shu 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!