Question: Program Specification An n x n matrix that is filled with the whole numbers 1, 2, 3, n2 is a magic square if the sum

 Program Specification An n x n matrix that is filled with

Program Specification An n x n matrix that is filled with the whole numbers 1, 2, 3, n2 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 Here is a magic square where n-3 4 Write a program that reads n numbers from standard input and tests whether they form a magic square when put into matrix form. The value of n is NOT an input to the program; n must be determined from the number of inputs. For example, the input that creates the example matrix above is: 816 357492 The output is a single word, "true" if the input produces a magic square, "false" otherwise. Your program may assume that each input token is a whole number The program must verify: The proper number of input values was provided. Each of the numbers between 1 and n' occurs exactly once in the input. When the numbers are arranged in a matrix, the sum of the 2. e rows, ecolumns and diagonals must be the same value

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!