114 void fillDoubly(int square[20][20], int n){
115
116 int i, j, k=0, l=0, counter=0, test[400]={0}, diff=n/4-1;
117
118 for(i=0;i<n;i++) //first nested for loops for part 1)
119 for(j=0;j<n;j++){
120 counter++;
121 if( i=j || j=(n-1-i) ){
122 {
123 square[i][j] = counter;
124 test[counter-1] = 1;
125 }
126 }
127 }
128
129 for(i=n-1;i>=0;i--) // for part 2)
130 for(j=n-1;j>=0;j--){
131 if(square[i][j]==0){
132 while(test[k]!=0){
133 k++;
134 }
135 test[k]=1;
136 square[i][j]=k+1;
137 }
138 }
139 }
So basically, I have to generate magic square's of order 4 i.e. the rows and columns are divisible by 4.
I was provided the algorithm which is
- to traverse the array and fill in the diagonal subsets
- to traverse the array backwards and fill in the rest
I've done the 4x4 array with the above code and this extends to 8x8,12x12 etc. but I'm stuck at part 1) which is to fill in the diagonal subsets(e.g. split 8x8 into 4x4 and take that diagonal instead)...I'm not sure how to do that, only managed to fill in the diagonal itself
if( i=j || j=(n-1-i) ){
tldr, The above is the condition I use to know if it's diagonal, any suggestions how I can change the condition to know if it's the diagonal subset not diagonal?
Thanks