Salam Alakom everybody,
I have a program that I would like to write and wonder if i can get a help with it from any expert in this forum. the description of the program is below
create a program that will fill in the numbers of a magic square . A magic square is a n x n grid in which the numbers 1, 2, 3, ….. n2 appear exactly one time, the sum of the each of the columns equals a specific number, the sum of each of the rows equals the same number, and the sum of each of the diagonals equals the same number. Below is an example for a 3 x 3 grid and a 5 x 5 grid.
Note that the rows (4 + 3 + 8, 9 + 5 + 1, and 2 + 7 + 6), columns (4 + 9 + 2, 3 + 5 + 7, and 8 + 1 + 6), and diagonals (8 + 5 + 2, and 4 + 5 + 6) sum up to 15 for the 3 x 3 grid. The sum for the 5 x 5 grid is 65.
An n x n square, where n is any odd integer > 0, can be filled using the following rules (you will only get credit if you follow these rules).
¨ Let k be an integer that has the values from 1 to n2.
¨ Place one (1) in the last column, middle row.
¨ Next continue to fill the grid by placing k + 1 one column to the right and one row down from where k was placed except when one of the following occurs:
1. if a move takes you below the bottom row in the jth column, then place k + 1 in the top row of the jth column;
2. if a move takes you outside to the right of the ith row, then place k + 1 in the 1st (left) column of the ith row;
3. or if a move takes you to a cell that is already occupied or outside the cell in the lower right corner, then k +1 should be placed immediately to the left of k.
Your program should be able to fill out any n x n grid where n is an odd number less than twenty that the user enters using the steps given above (you will not receive any credit if you use any other method). Your program should repeatedly prompt the user for a new number if the user enters and invalid number for n. Once the grid has been filled, your program should output the magic square using a function and output the sum for rows and columns. The program should also allow the user to choose another grid size without exiting the program.
Your program should have a function that will initialize all the elements of the array to 0 or a negative number before each run so you can tell when a cell has a number in it already and a function to output the elements of the arrays to the screen. Make sure your function parameters have different names than the variables used in main.
more details are in the file attached.