Originally Posted by

**laserlight**
What have you tried?

Wh1-type of CheckMagic that tests the fact that the box (no matrix) magic or not.

To not have the matrix box, so that the number of lines equal to the number of columns

And the total numbers in each line is equal to the total numbers in each column and is equal to the total number of the country and is equal to the hard Magic

Hard = (n * n * n + n) \ 2, where N is the rank of the matrix means the number of lines or columns

The condition here is that we do not repeat the number in the matrix all of Marin

That we have imposed a bilateral matrix size n any number of lines and columns

int rcl [] [] = new int [n] [n];

for (int i = 1; i <= n; i + +)

for (int j = 1; j <= n; j + +)

Enter the data matrix

And grown up a counter to calculate the total number of the line that we enter as well as the total column prepared we are entering

On the assumption that among the total number of the line is d and among the total number of column is fixed and t is the magic symbol th

if (d == th & & t == th & & rcl [i]! = rcl [j +1])

rcl [i]! = rcl [j +1] we want here not to repeat the number twice

Be a magic box or the matrix

else

Is not a magic bullet

2_ What is the complexity of CheckMagic.

Complexity is

Complexity of the complexity of the episode I * The second condition was the last

Means the complexity class will be welcomed

O (N * N)

3 - Write a recursive procedure that you love the magic box of dimension n and in accordance with the algorithm described above.

Procedure RecMagic (x: 1 .. nmax; p, q: 1 .. nmax);

(X represents the number to be filled in and represent each of the p and q are the site that will put the number in it)

Code:

public int [,] magic_square (int x, int p, int q)
(
int [,] sq = new int [x, x];
int c = 1;
for (int i = p, j = q; c <(x * x) +1; i -, j + +)
(
if (j == x)
(
j = 0;
)
if (i == -1)
(
i = x-1;
)
if (sq [i, j]! = 0)
(
i + +; j -;
if (j == -1)
(
j = x-1;
)
if (i == x)
(
i = 0;
)
i + +;
if (i == x)
(
i = 0;
)
)
sq [i, j] = c;
c + +;
)
return sq;
)