Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | May 2017 |
Last Sign in: | 305 Weeks Ago, 6 Days Ago |
Questions Answered: | 66690 |
Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
An n x n matrix that is filled with the whole 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.
Here is a magic square where n = 3:
8 1 6
3 5 7
4 9 2
Write a program that reads n^2 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: 8 1 6 3 5 7 4 9 2.
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:
1. The proper number of input values was provided.
2. Each of the numbers between 1 and n2 occurs exactly once in the input.
3. When the numbers are arranged in a matrix,
Ac€?c the sum of the rows,
Ac€?c columns,
Ac€?c and diagonals
must be the same value
Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â----------- Th-----------ank----------- Yo-----------u f-----------or -----------usi-----------ng -----------our----------- we-----------bsi-----------te -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill-----------