Question: C++ Write an algorithm that does the following: Given a two-dimensional matrix, determine if it is a magic square. The function IsMagicSquare will just receive

C++

Write an algorithm that does the following:

Given a two-dimensional matrix, determine if it is a magic square. The function IsMagicSquare will just receive a 2d matrix. It is your job to make sure it complies with all the magic square requirements listed in the paragraph below. Return true if the matrix is a magic square. Otherwise, return false.

What is a magic square?

A magic square is a n x n square grid (where n is the number of cells on each side) filled with distinct positive integers in the range 1, 2, ..., n such that each cell contains a different integer and the sum of the integers in each row, column and diagonal is equal. The sum is called the magic constant or magic sum of the magic square.

An example with 15 as magic constant

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!