csc1253proj05s15.pdf

# csc1253proj05s15.pdf - Magic Squares CSc 1253 Project 5...

• Notes
• 5

This preview shows page 1 - 2 out of 5 pages.

Magic Squares CSc 1253: Project # 5 Generating Magic Squares Out: 3/26 Due: 4/20 by 11:50 PM Learning Objectives Using Arrays Text File Output More on Loops Definition 1. A magic square is a square table of numbers consisting of the distinct positive integers 1 , 2 , · · · ,n 2 arranged such that the sum of the n numbers in any horizontal, vertical, or diagonal line is always the same number. The table below is a 3 × 3 magic square since every row, column and diagonal sums up to 15. 8 1 6 3 5 7 4 9 2 In this project, you will generate an n × n magic square, where n is a positive odd number that represents the dimension of the magic square. In order to store the table in a one-dimensional array, we need a mapping ( row,col ) index since we will need to store the square in the array and write the contents of the array in tabular format. Suppose the first row of an n × n table, starting from the top-most row, is row 0, the second row is row 1, etc. Also, suppose the first column of the table, starting from the left-most column, is column 0, the second column is column 1, etc. Then these mapping are true: Table [ row,col ] Array [ n × row + col ] Array [ index ] Table [ index/n,index mod n ] Here, n represents the dimension of the magic square. For this project, you may assume that the dimension of the magic square can be no more than 1000; that is, the array storing the entries in the magic square has a capacity of at most 1 million entries. Define a global integer constant call MAX SIZE whose value is 1 million to represent this value.

Subscribe to view the full document.

• Fall '08
• Staff
• Integers, Natural number

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern