Programming Homework Help

Programming Homework Help. C++ algorithms, programming assignment help

Write code that fulfills the requirements in the problem description.

Ensure that the the output from the function is properly rendered using a printing method like cout.

Also include all libraries and incidentals used (standard “using namespace std” etc)

Problem Description

In mathematics, a magic square of order N is an arrangement N^2 numbers, usually distinct integers in a square, such that the N numbers in all rows, all columns, and both diagonals sum to the same constant.

John is interested in the process of creating a magic square. He knew about De La Loubère’s Algorithm and would like to ask for your help to make a program which is able to create a magic square of order N. Here is the algorithm:

1. Place the first number in the middle cell of the top row.

2. Successive numbers are inserted into the square in a diagonal line sloping upwards and to the right.

3. When it is at the top row, the next number goes into the bottom row as if it were directly above the top row.

4. When it is at the right hand column, the next number goes into the extreme left column as if it were directly to the right of the right hand column.

5. When a cell to go into is already filled, or when the top right hand cell is reached, the next number drops to the cell directly below.

Given an odd number N, create the magic square using the given algorithm.

Input

The input contains one integer, N (1 <= N <= 19).

Output

Output the magic square with the same format as sample output when N is 3. (There are N lines in the output, each line has N numbers. There is at least a space character between 2 numbers. There is no space after the last number in a line.)

Sample Input

3

Sample Output

8 1 6

3 5 7

4 9 2

Program Development

The matrix printed should have all entries aligned properly

Programming Homework Help

 
"Our Prices Start at $11.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!"