0.0 General‎ > ‎Assignments‎ > ‎

Magic Squares

OBJECTIVES:

The student will become familiar with organizing data in tabular form (2-D arrays), counting and the concept of wrap-around.

DESCRIPTION:

Create a MAGIC SQUARE, which must be of size 5 (rows and columns) or greater and must be an ODD number. A MAGIC SQUARE has the same SUM for each of its rows, columns and major diagonals.

Use a Object approach to build this solution.

Input:
  1. Size of square (5 x 5, 7 x 7 or greater). 
  2. Starting number . 
  3. Increment (amount to add on each time). 
Output:
  1. The input information with a description for each. 
  2. The "MAGIC SQUARE" properly spaced. 

Sample Output:

Size 5

Starting Number 1 Increment 1

MAGIC SQUARE

17

24

1

8

15

23

5

7

14

16

4

6

13

20

22

10

12

19

21

3

11

18

25

2

9

 


Rules:

  1. Start with the top row and middle column.
  2. Move up one row and right one column.
  3. If you go off the top come back on the bottom.
  4. If you go off the right side come back on the left side.
  5. If a square is already used then use the square below the previous square.
Subpages (1): Magic Squares: OOPs
Comments