Question: In C++ Write a program that will take a 3x3 matrix and test to see if it is a magic square. A 3x3 matrix is
In C++ Write a program that will take a 3x3 matrix and test to see if it is a magic square. A 3x3 matrix is magic if all of the following sums are the same: each row, each column, and both diagonals.
The following example is a magic square because everything adds up to the same number (2+7+6=15, 9+5+1=15, 4+3+8=15, 2+9+4=15, 7+5+3=15, 6+1+8=15, 2+5+8=15, and 4+5+6=15).
| 2 | 7 | 6 |
| 9 | 5 | 1 |
| 4 | 3 | 8 |
Use functions dont put everything in main
Use loops to calculate the sums dont hardcode the calculation. For example, you dont want something like sum = matrix[0][0] + matrix[0][1] + matrix[0][2]. That is hard to update if we change the size of the array
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
