magic squares, an nX n matrix that is filled with the numbers 1,2,3... n^2 is a
ID: 3530776 • Letter: M
Question
magic squares, an nX n matrix that is filled with the numbers 1,2,3... n^2 is a magic square if the sum of the element in each down, in each column, and in the two diagonals is the same value. write a program that reads in 16 values from the keyboard and testes whether they form a magic square when put into a 4 x 4 array. you need to test two features: 1. does each of the number 1,2 ..., 16 occur in the user input? 2. when the numbers are put into a square, are the sums of the rows, columns and diagnol equal to each other?Explanation / Answer
#include#includeusing namespace std; int main() { int n; cout>n; int MagicSquare[n][n]; int newRow, newCol; // Set the indices for the middle of the bottom i int i =0 ; int j= n / 2; // Fill each element of the array using the magic array for ( int value = 1; valueRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.