Chapter 6: Problem 20
Magic squares. An \(n \times n\) matrix that is filled with the numbers \(1,2,3, \ldots, n^{2}\) is a magic square if the sum of the clements in each row, in cach column, and in the two diagonals is the same value. Write a program that reads in 16 values from the keyboard and tests whether they form a magic square when put into a \(4 \times 4\) table. You need to test two features: 1\. Does each of the numbers \(1,2, \ldots, 16\) occur in the user input? 2\. When the numbers are put into a square, are the sums of the rows, columns, and diagonals equal to each other?
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.