Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

1. What are the marketing implications of this situation?

Answered: 1 week ago