Write a program that tests whether a 3 x 3 array, which you may hard code, is a magic square. A magic square is an N x N matrix of numbers in which every number from 1 to N*N must appear just once, and every row, column, and diagonal must add up to the same total.
So this is what i do.
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
char quit;
int main( )
{
//declaring the 2d matrix arrays
float matrix1[3][3];
float matrix2[3][3];
cout << "Week 5 Assignment, A-5B of two 2d 3x3 matrixes by DR. " <<endl;
//*************assigning numbers to the first matrix*********
for (int row = 0; row < 3; row++)
for (int column = 0; column < 3; column++)
{
cout << "Enter value for row " <<row+1 << " column " <<column+1 << ": " << endl;
cin >> matrix1[row][column];
}
int row, column;
for (row = 0; row < 3; row++)
{
for (column = 0; column < 3; column++)
cout << matrix1[row][column];
cout << endl;
}
“this is what I am missing, I don’t know how to locate each the number. I want to write a if loop that do the following.
If
row 11 + row 12 + row 13 = 15
row 22 + row 21 + row 23 = 15
until I tried all write every row every column and diagonally it adds to 15.
A if loop that make sure row 11 isn’t equal any of the other number and do it for the other 8 numbers in the magic square.
Lastly if the condition from above are satisfy, cout<<” it is a magic square”;