Sorting and 2d Arrays – Geometry – Problem #4

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: hard

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

Back to Lab Problems
Sorting and 2d Arrays/Geometry/Problem #4

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #4

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.