need help new to C programming

From: celsius (atcelsius_at_yahoo.co.uk)
Date: 02/28/04


Date: 28 Feb 2004 10:36:09 -0800

given below is a program to find magic square of odd order n, but it
is not giving the desired output.could someone please help me

  #include<stdlib.h>
  #include<stdio.h>

  int *m;
 
  int main(void)
  {
     int i,n;
     int val,row,col;
     int n_row,n_col;

     puts("enter the order of the magic square....");
     scanf("%d",&n);

     if( (n%2) == 0)
     {
       puts("order of magic square an odd number:");
       exit(1);
     }

     m = (int*)malloc( (n * n) * sizeof(int));
         
     if(!m)
         {
        puts("memory allocation failed...:");
                exit(1);
          
         }
         
         for(i = 0;i < (n * n);i++)
     *(m+i) = 0;

     row = 0;
     col = n/2;

     *(m +(row + col) ) = 1;

     for(val=2; val <= (n*n); val++)
     {
        if(row > 1)
          n_row = row-1;
        else
          n_row = (n-1);

        if(col < n-1)
           n_col = col+1;
         else
           n_col = 0;

        if( *(m + (n_row *n) + n_col) != 0)
        {
            n_row = row+1;
            n_col = col;
        }

        *(m + (n_row * n) + n_col) = val;
        row = n_row;
        col = n_col;

     }

     for(i = 0;i < (n * n);i++)
     {
       if( (i%n) == 0 )
       puts("");

       printf("%d \t",*(m+i));
     }

     free(m);
     return(0);
  }