Sorting and 2d Arrays – Geometry – Problem #4
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Write a program which reads an integer n, and then reads a n x n integer matrix such that it is filled up with the numbers 1 to n^2.. Each number can be used only once. Assume that the users follows these rules. Now, check and print whether the matrix is a magic square. A magic square is the one where the sum of each of the rows, each of the columns and each of the two major diagonals is the same. Here is an example of a 3 x 3 magic square: 4 9 2 3 5 7 8 1 6 Here is an example of a 4 x 4 magic square: 7 12 1 14 2 13 8 11 16 3 10 5 9 6 15 4