Write a program to construct an n x n magic square

Assignment Help Basic Computer Science
Reference no: EM131788431

A magic square is an n X n matrix in which each of the integers 1,2,3, ..., nZ appears exactly once and all column sums, row sums, and diagonal sums are equal. For example, the following is a 5 X 5 magic square in which all the rows, columns, and diagonals add up to 65:

272_magic square is an n X n matrix.png

The following is a procedure for constructing an n x n magic square for any odd integer n. Place 1 in the middle of the top row. Then, after integer k has been placed, move up one row and one column to the right to place the next integer k + 1, unless one of the following occurs:

  • If a move takes you above the top row in the jth column, move to the bottom of the jth column and place k + 1 there.
  • If a move takes you outside to the right of the square in the throw, place k + 1 in the ith row at the left side.
  • If a move takes you to an already filled square or if you move out of the square at the upper right-hand corner, place k + 1 immediately below k.
  • Write a program to construct an n X n magic square for any odd value of n.

Reference no: EM131788431

Questions Cloud

Demographic study of the metropolitan area : A demographic study of the metropolitan area around Dog patch divided it into three regions-urban, suburban, and exurban-and published the following table
Determine what will the decision be using payback method : The Short-Line Railroad is considering a $100,000 investment in either of two companies. The cash flows are as follows.
What would be recorded on december financial statements : SSM Ltd. has determined that its Southwest division. What would be recorded on December 31, 20X5 financial statements, for the Southwest division?
Calculate and display sum : Write a program to read two m X n matrices, display them, and calculate and display their sum.
Write a program to construct an n x n magic square : Write a program to construct an n X n magic square for any odd value of n.
Calculate companys basic and fully diluted earning per share : Calculate the company's basic and fully diluted earnings per share.
Determine the internal rate of return using interpolation : Home Security Systems is analyzing the purchase of manufacturing equipment that will cost $40,000. The annual cash inflows for the next three years will be.
Find and report the equation of the regression line : Consider a person who gets $45,000 in City A. Without doing any calculation, state whether the predicted salary in City B would be higher, lower.
What are computer performance parameters : BN103 Platform Technologies Assignment. What are computer performance parameters, Discuss all the parameters that affects computer performance

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd