Home‎ > ‎Assignments‎ > ‎

Magic Square

Programming Assignment

A magic square is a square matrix (array) in which each row, column, and diagonal add up to the same value.
For example, 

 8 1 6
 3 5 7
 4 9 2

Write a program which will read in a square matrix of any size and determine whether is is a "magic square." Your program should be efficient and flexible.

Use the above matrix and at least one other (non-magic) matrix as data in the same computer run.  
Try this one for an "almost" magic square:

 123
 231
 312

Extra points:  After you have the program working, re code it to use functions to sum across a single row and down a single column.  You may wish to wait a couple of weeks for this.

Comments