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