pls guide me to write a program in c to generate a magic square of size n*n , where n is odd

A magic square is an n*n matrix of integer from 1 to n^2, where n is odd, such that the sum of every row, column and diagonal is same.

The rule is - Start with 1 in the middle of the first row; then go up and left , assigning nos. in increasing order to empty squares; if u fall off the square i.e. if if it is the first column, move to last column in the same row and similarly handle the first row; if the square is occupied, move down instead and continue