Question: Can someone please help with this question 1. Any nx n magic square (where n is an odd integer) consists of an nxn matrix whose
Can someone please help with this question
1. Any nx n magic square (where n is an odd integer) consists of an nxn matrix whose elements contain the numbers 1, 2, 3,..., n such that the sum of each row, column and diagonal is equal to #1). For example, the following magic square for n = 3, with the sum of each row, column and diagonal being 90%+1) = 15: 618 294 (a) An algorithm for generating an n x n magic square for odd n is as follows: NOTE: Assume the rows and columns wrap around (i.e., moving one column left from the first column gives the last column) Create a 2 dimensional array of size n by n and set all values to be 0 Set = 1, y = 2 (row 1 and column ). Insert 1 at 1, v for i = 2 to n do if element : -1,7 -1 is empty (i.e. = 0) then =:-1, y-y-1 else r = x+1, y = y end if Insert i at ry end for Write a command line application that prompts the user for an odd integer and displays a magic square of that size to standard output (i.e. the command line). (HINTS: Recall that Java arrays start at the element 0; it may help to define a class to store a square matrix)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
