Ok I solved the problem using this code : (I can't see the array elements in debugging mode but it works)
Code:
#include <stdio.h>
#include <stdbool.h>
int main (int argc, const char * argv[]) {
// insert code here...
int size;
int row = 0;
int column = 2;
int rows;
int columns;
//get user input
printf("This program creates a magic square of a specific size.\n");
printf("The size must be an odd number between 1 and 99.\n");
printf("Enter size of magic square: ");
scanf("%d", &size);
int myArray[size][size];
for (rows = 0; rows < size; rows++) {
for (columns = 0; columns < size; columns++) {
myArray[rows][columns] = 0;
}
}
myArray[row][column] = 1;
for (int counter = 2; counter <= size * size; counter++) {
if (row == 0)
row = size -1;
else
row = row - 1;
if (column == size - 1)
column = 0;
else
column = column + 1;
if (!myArray[row][column] == 0)
{
row = (row + 2) % size;
if (column == 0)
column = size - 1;
else
column = column - 1;
}
myArray[row][column] = counter;
}
for (rows = 0; rows < size; rows++) {
for (columns = 0; columns < size; columns++) {
printf("%2d ", myArray[rows][columns]);
}
printf("\n");
}
}