The Magic Constant
EasyAcc. 98.5%
+20 XP 8
Celestial Harmony
A magic square of order $N$ is an $N imes N$ grid containing numbers $1, 2, dots, N^2$ such that the sum of each row, column, and diagonal is the same. This constant is called the Magic Constant. Formula: $M = n(n^2 + 1) / 2$.
The Assignment
Your function receives a parameter n.
- Use a loop to calculate the sum of numbers from 1 up to $n^2$.
- Divide that sum by
n. - Print the resulting Magic Constant.
01EXAMPLE 1
Input
n = 3Output
15Explanation: 3(9+1)/2 = 15.
Constraints
- Use a loop to find the total sum of N^2 elements.
- Print the final integer.
MathLoops
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
n3
Expected Output
15
Click RUN to test your solution