Write a program that reads a square array of integers and


Problem

A magic square is a square array of integers such that the sum of every row, the sum of every column, and sum of each of the two diagonals are all equal. Two magic squares are shown in Figure 1.5.

2353_Two magic squares.jpg

(a) Write a program that reads a square array of integers and determines whether or not it is a magic square.

(b) Write a program that generates a magic square by the following method. This method works only when the size of the square is an odd number. Start by placing 1 in the middle of the top row. Write down successive integers 2, 3, ... along a diagonal going upward and to the right. When you reach the top row (as you do immediately since 1 is in the top row), continue to the bottom row as though the bottom row were immediately above the top row. When you reach the rightmost column, continue to the leftmost column as though it were immediately to the right of the rightmost one. When you reach a position that is already occupied, instead drop straight down one position from the previous number to insert the new one. The 5 × 5 magic square constructed by this method is shown in Figure 1.5.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write a program that reads a square array of integers and
Reference No:- TGS02642867

Expected delivery within 24 Hours