+ 1
C program magic square
A 2-dimensional array is called a magic square if the sum of the numbers along any row, column or diagonal is the same. For example, the following is a magic square because the numbers along any of the 4 rows, 4 columns or 2 diagonals is 34 (i.e. (1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16)/4 = 34). 1. The user has a choice to input his/her own numbers into a 4 X 4 matrix or to request the program randomly generate a 4 X 4 matrix. Make sure that the randomly generated matrix contains the numbers 1 to 16 and each element is different from other numbers. 2. The program must have the function int magic(int array[4][4]) which takes as parameter a 4×4 array of integers and returns 1 if the numbers in the array form a magic square, 0 otherwise.
1 Respuesta
+ 2
ashi Show your attempts.