奇數階魔方陣

 











 main( argc,  *argv[])
{
     i;
     n = ;
     width;
     row, col;
     *array;
     buf[];

     (argc != ) {
        printf();
        printf(, argv[]);
         ;
    }

    n = atoi(argv[]);
     ((n & ) == ) {
        printf();
         ;
    }

    array = ( *)malloc(n * n * ());
     (array == ) {
        perror();
         ;
    }

     (i = ; i < n * n; i++) {
        array[i] = ;
    }

     (i = , row = , col = n >> ; i <= n * n; i++) {
        array[row * n + col] = i;
         (array[(row + n - ) % n * n + (col + ) % n]) {
            row = (row + ) % n;
        }  {
            row = (row + n - ) % n;
            col = (col + ) % n;
        }
    }

    sprintf(buf, , n * n);
    width =  + strlen(buf);

     (row = ; row < n; row++) {
         (col = ; col < n; col++) {
            printf(, width, array[row * n + col]);
        }
        printf();
    }
     ;
}
=================================
=================================

楊輝魔方陣

楊輝《續古摘奇算經》(1275年)
九子斜排 上下對易 左右相更 四維挺進
戴九履一 左三右七 二四為肩 六八為足
http://residence.educities.edu.tw/mario123/problems/magic-2.htm

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章