As early as 650 BC, mathematicians had been composing magic squares, a sequence of n numbers arranged in a square such that all rows, columns, and diagonals sum to the same constant. Used in China, India, and Arab countries for centuries, artist Albrecht Durer\'s engraving Melencolia I (year: 1514) is considered the first time a magic square appears in European art. Each row, column, and diagonal of Durer\'s magic square sums to 34. In addition, each quadrant, the center four squares, and the corner squares all sum to 34. An example of a magic square\" is displayed below. 16 3 2 13 5 10 11 8 9 6 7 12 4 15 141 Write a program to prove a series of numbers is indeed a 4 x 4 magic square. Your program should complete the following steps, in this order: (a) Ask the user to enter their proposed magic square in a single input statement (e.g.. 11234;5 678;9 10 11 12, 13 14 15 16]-note this example is a 4 x 4 matrix, but NOT a magic square). You may assume the user will enter whole numbers; they will not enter either decimal values or text. (b) Check that all values are positive: t for-loop or nested for-loop required in the solution. If one or more of the values in the matrix are negative or zero, issue a statement to the command window informing the user of the mistake and exit the program. This check should work even if the user does not enter a 4 x 4 matrix; it should work regardless of the size of matrix entered. (c) Check for an arrangement of 4 4 . If the matrix is not a 4 × 4, issue a statement to the command window informing the user of the mistake and exit the program.
#include<stdio.h>
#include<conio.h>
int main() {
int size = 4;
int matrix[3][3];
int row, column = 0;
int sum, sum1, sum2;
int flag = 0;
printf(\"\ Enter matrix : \");
for (row = 0; row < size; row++) {
for (column = 0; column < size; column++)
scanf(\"%d\", &matrix[row][column]);
}
printf(\"Entered matrix is : \ \");
for (row = 0; row < size; row++) {
printf(\"\ \");
for (column = 0; column < size; column++) {
printf(\"\\t%d\", matrix[row][column]);
}
}
//For diagonal elements
sum = 0;
for (row = 0; row < size; row++) {
for (column = 0; column < size; column++) {
if (row == column)
sum = sum + matrix[row][column];
}
}
//For Rows
for (row = 0; row < size; row++) {
sum1 = 0;
for (column = 0; column < size; column++) {
sum1 = sum1 + matrix[row][column];
}
if (sum == sum1)
flag = 1;
else {
flag = 0;
break;
}
}
//For Columns
for (row = 0; row < size; row++) {
sum2 = 0;
for (column = 0; column < size; column++) {
sum2 = sum2 + matrix[column][row];
}
if (sum == sum2)
flag = 1;
else {
flag = 0;
break;
}
}
if (flag == 1)
printf(\"\ Magic square\");
else
printf(\"\ No Magic square\");
return 0;
}