Can there be a magic square with equal diagonal sums different from equal row and column sums? I got a task in programming a program that can detect whether a 4x4 square is a magic square or not. At first, I wrote code that met the requirements for all given examples but I noticed one flaw. I used 2 variables to indicate sums. I used them once to calculate the sums of the rows and columns and compare them, then I reset them back to 0 and used them to calculate the diagonal sums and check if they were equal. The thing was, is that I did not actually compare the diagonal sums to the original row and column sums, and that got me thinking. Can there exist a "magic square" where the diagonal sums are equal and the row and column sums are equal, but the diagonal sums are different from the row and column sums? Is there any actual way to prove this? I tried to come up with examples but nothing came to me. An example would disprove this and make me rewrite my code. For simplicity, I would rather know about a 4x4 square, but if you can I'll be happy to hear a proof for any $n$ x $n$ square. Thanks in advance.

Edit: I already check to see if the integers are all different, so I'd rather know if one exists where all of the integers are different.
I assume you are looking for one with not just 'all different numbers', for that is trivial: just take any $n \times n$ magic square and add the same amount (larger than $n^2$) to the cells on the diagonals. For example, you can go from:

\begin{array}{|c|c|c|c|}
\hline
16&amp;3&amp;2&amp;13\\
\hline
5&amp;10&amp;11&amp;8\\
\hline
9&amp;6&amp;7&amp;12\\
\hline
4&amp;15&amp;14&amp;1\\
\hline
\end{array}

to:

\begin{array}{|c|c|c|c|}
\hline
116&amp;3&amp;2&amp;113\\
\hline
5&amp;110&amp;111&amp;8\\
\hline
9&amp;106&amp;107&amp;12\\
\hline
104&amp;15&amp;14&amp;101\\
\hline
\end{array}

... and that's just too easy!  So, I assume you mean that you have to use all numbers $1$ through $n^2$. 

Well, after trying a bunch of things I am fairly convinced that you cannot have a $4 \times 4$ square with numbers $1$ through $16$ where are rows and columns sum p to the same amount (this is actually called a 'semi-magic square') but where the diagonals sum up to the same amount, yet different from the rows and columns. In all $4 \times 4$ semi-magic squares that were not $4 \times 4$ magic squares that I looked at, I found the diagonals still adding up to exactly twice the sum of a row. I don't have a proof though that this is really impossible.

I did, however, find a $6 \times6$ square using numbers $1$ through $36$ with all rows and columns adding up to $111$ but both diagonals adding up to only $97$:

\begin{array}{|c|c|c|c|c|c|}
\hline
6&amp;34&amp;1&amp;28&amp;24&amp;18\\
\hline
14&amp;7&amp;36&amp;4&amp;20&amp;30\\
\hline
33&amp;3&amp;31&amp;2&amp;17&amp;25\\
\hline
27&amp;22&amp;23&amp;16&amp;12&amp;11\\
\hline
10&amp;13&amp;5&amp;35&amp;29&amp;19\\
\hline
21&amp;32&amp;15&amp;26&amp;9&amp;8\\
\hline
\end{array}

And so, the answer to your question is Yes!  (But no, I did not look at the $5 \times 5$ case (although my guess is that you can find an example of what you want for the $5 \times 5$ case and up), and no, I did not create this example in a systematic way: I started with a known semi-magic $6 \times 6$ square and kept swapping rows and columns in a semi-random fashion until I found this one).

Finally, in my research I found that there are many different kinds of magic squares (I had no idea!), such as these 'semi-magic squares' or 
'extremely magic squares', or .... but what you are asking about I did not see a name for. Given that they apparently exist you should definitely come up with a name for these!

EDIT

Aha! As I thought, it also works for $n=5$. Here is one:

\begin{array}{|c|c|c|c|c|}
\hline
19&amp;6&amp;15&amp;2&amp;23\\
\hline
9&amp;17&amp;10&amp;13&amp;16\\
\hline
21&amp;24&amp;14&amp;5&amp;1\\
\hline
4&amp;11&amp;8&amp;20&amp;22\\
\hline
12&amp;7&amp;18&amp;25&amp;3\\
\hline
\end{array}

Rows and columns sum to $65$, but columns sum to $73$

EDIT 2:  Aha!  I was wrong about the $4 \times 4$: it is possible to have one!! See Taneli Huuskonen's answer.
there is a geometrical method to systematically construct not even (2n+1) magic squares, quite easy, even by hand with a pen!
I will post an example for 5x5 and 7x7 squares, as soon as I get hold of a scanner. see below a 5x5 one
Greg



3 16 9 22 15
20 8 21 14 2
7 25 13 1 19
24 12 5 18 6
11 4 17 10 23