English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

以下是5*5的魔方陣程式碼,但執行結果並不是正確的
請知道的人幫我找出錯誤,謝謝!@@"
Private Sub Form_Click()

Dim M, I, J, X1, Y1 As Integer
Dim A(5, 5) As Integer

X = 1: Y = 3
For M = 1 To 25
A(X, Y) = M
X1 = X - 1: Y1 = Y + 1
If X1 = 0 Then X1 = 5
If Y1 = 6 Then Y1 = 1
If A(X1, Y1) <> 0 Then
X1 = X + 1
Y1 = Y
If X1 = 6 Then X1 = 1
End If
X = X1: Y = Y1
Next M
'印出結果
For I = 1 To 5
For J = 1 To 5
Print A(I, J); Tab(J * 5);
Next J
Print
Next I

End Sub

答案為
24 15 1  17 8
14 5  16 7  23
4  20 6  22 13
19 10 21 12 3
9  25 11 2  18

2007-03-20 19:29:24 · 4 個解答 · 發問者 piggy 1 in 電腦與網際網路 程式設計

4 個解答

答案不對吧!1234321兄~你要不要再驗算一下..

2007-03-21 02:30:46 補充:
你只要多加一行
If Y1 = 0 Then Y1 = 5
就OK了!
-----------------
Private Sub Form_Click()
Dim M, I, J, X1, Y1 As Integer
Dim A(5, 5) As Integer

X = 1: Y = 3
For M = 1 To 25
A(X, Y) = M
X1 = X - 1: Y1 = Y 1

If X1 = 0 Then X1 = 5
If Y1 = 6 Then Y1 = 1

If A(X1, Y1) <> 0 Then
X1 = X 1
Y1 = Y
If X1 = 6 Then X1 = 1
If Y1 = 0 Then Y1 = 5 '●●●多加這行●●●
End If
X = X1: Y = Y1
Next M
'印出結果
For I = 1 To 5
For J = 1 To 5
Print A(I, J); Tab(J * 5);
Next J
Print
Next I
End Sub

答案為
17 24 1  8  15
23 5  7  14 16
4  6  13 20 22
10 12 19 21 3
11 18 25 2  9

2007-03-21 19:20:06 補充:
to:1234321
哦~原來如此~是我被誤導了~
抱歉~錯怪你了~

2007-03-20 22:30:46 · answer #1 · answered by 幽靈 5 · 0 0

尤怪之家:http://www.shes.hcc.edu.tw/~oddest/

2007-03-21 08:42:36 · answer #2 · answered by W.J.S. 7 · 0 0

有魔方陣數學的解法嗎???我有興趣想知道@@"

2007-03-21 07:10:04 · answer #3 · answered by no_nickname 2 · 0 0

私人子形成Click( )

模糊M,我,J,X1,作為整數的Y1
使A(5 作為整數模糊,5 )

X = 1: Y = 3
對於M = 1到25
( X,Y ) = M
X1 = X -- 1: Y1 = Y + 1
如果X1 = 0然後X1 = 5
如果Y1 = 6然後Y1 = 1
如果> ( X1,Y1 ) < 0那時
X1 = X + 1
Y1 = Y
如果X1 = 6然後X1 = 1
結束如果
X = X1: Y = Y1
其次M
‘印出結果
對於I = 1到5
對於J = 1到5
列印A (我,J ); 標籤( J * 5 );
其次J
列印
其次I

結束子
答案為
24 15 1  17 8
14 5  16 7  23
4  20 6  22 13
19 10 21 12 3
9  25 11 2  18

我不知道你在問舌??

2007-03-20 19:37:39 · answer #4 · answered by ? 3 · 0 0

fedest.com, questions and answers