Computer Science, asked by pp1996, 5 hours ago

In recreational mathematics, a magic square is an N X N square grid (where N is the number of cells on each side) filled with distinct positive integers in the range 1,2,...,n^2 such that each cell contains a different integer and the sum of the integers in each row, column and diagonal is equal.

Given a square matrix as input, determine whether it is a magic square or not. Print "ITS A MAGIC!" if the square matrix is a magic square, otherwise print "NO MAGIC".

Assumptions:

1) All the elements of the square matrix are different and in the range, 1,2,...,n^2. Hence need not be verified.

2) The row and column size are to be accepted in R and C, as integer inputs, and R & C, both are >=2, even though it is a square matrix. In any case, R is equal to C and need not be verified.





=15

2 7 6 =15
9 5 1 =15
4 3 8 =15
=15 =15 =15 =15

Answers

Answered by Goldenstar06
0

Answer:

A magic square of order n is an arrangement of n2 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. A magic square contains the integers from 1 to n2.

The constant sum in every row, column and diagonal are called the magic constant or magic sum, M. The magic constant of a normal magic square depends only on n and has the following value:

M = n(n2+1)/2

For normal magic squares of order n = 3, 4, 5, ...,

the magic constants are: 15, 34, 65, 111,

Similar questions