主题:[活动]幻方
神鬼天王
[专家分:30] 发布于 2009-09-13 13:02:00
幻方问题
回复列表 (共1个回复)
沙发
phile [专家分:2310] 发布于 2009-09-13 13:03:00
CLS
INPUT N
DIM A(N, N)
I = 1
J = N \ 2 + 1
I1 = I
J1 = J
A(I, J) = 1
FOR K = 2 TO N * N
I1 = I - 1
IF I1 < 1 THEN I1 = N
J1 = J + 1
IF J1 > N THEN J1 = 1
IF A(I1, J1) <> 0 THEN
I = I + 1
ELSE
I = I1: J = J1
END IF
A(I, J) = K
NEXT K
FOR I = 1 TO N
FOR J = 1 TO N
PRINT USING "###"; A(I, J);
NEXT J
PRINT
NEXT I
我来回复