for(row = 3 ; row >= 0; row--){
result = matrix[row][row] +result;
}
First iteration x = 3
result = matrix[3][3];
Second iteration x = 2
result = matrix[3][3] + matrix[2][2];
Third iteration x = 1
result = matrix[3][3]+ matrix[2][2] + matrix[1][1];
Fourth iteration x = 0;
result = matrix[3][3] + matrix[2][2] + matrix[1][1] + matrix[0][0];
So result should be
1 + 7 + 10 + 16
= 34
I could think that perhaps an array of results
result[0] = matrix[3][3];
result[1]= result[0] + matrix[2][2];
result[2] = result[1] + matrix[1][1];
result[3] = result[2] + matrix[0][0];
for (int x = 0; x < =3; x++)
{
if (x ==0)
result[x] = matrix[3-x][3-x];
else
{
result[x] = result[x-1] + matrix[3-x][3-x];
}
}
Now check if result[3] = magic.