As early as 650 BC, mathematicians had been composing magic squares, a sequence of n numbers arranged in a square such that all rows, columns, and diagonals sum to the same constant. Used in China,...


As early as 650 BC, mathematicians had been composing magic squares, a sequence of n


numbers arranged in a square such that all rows, columns, and diagonals sum to the same


constant. Used in China, India, and Arab countries for centuries, artist Albrecht Dürer’s


engraving Melencolia I (year: 1514) is considered the first time a magic square appears in


European art. Each row, column, and diagonal of Dürer’s magic square sums to 34. In addi


tion, each quadrant, the center four squares, and the corner squares all sum to 34. An


example of a “magic square” is displayed below.


Write a program to prove a series of numbers is indeed a 4 * 4 magic square. Your program should complete the following steps, in this order:


(a) Ask the user to enter their proposed magic square in a single input statement (e.g.,


[1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]—note this example is a 4 * 4 matrix, but NOT


a magic square). You may assume the user will enter whole numbers; they will not enter


either decimal values or text.


(b) Check that all values are positive; ** for-loop or nested for-loop required in the solution. If one or more of the values in the matrix are negative or zero, issue a statement to


the command window informing the user of the mistake and exit the program. This


check should work even if the user does not enter a 4 * 4 matrix; it should work


regardless of the size of matrix entered.


(c) Check for an arrangement of 4 * 4 . If the matrix is not a 4 * 4 , issue a statement to


the command window informing the user of the mistake and exit the program.


(d) Determine if the matrix is a form of a magic square. The minimum requirement to be


classified as a magic square is each row and column sums to the same value. ** forloop or nested for-loop required in the solution. If this criteria is not met, issue a statement to the command window informing the user they have not entered a magic square


and exit the program.


(e) Determine the classification of the magic square using the following requirements:

Nov 24, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here