# 5*5的方格N1跟N2

X = Int(Rnd * 25) + 1

N1 = X \ 5

N2 = X Mod 5 + 1

a(N1, N2) = I

Dim a(5, 5)

Dim b(122) As Integer

Dim X As Integer

Randomize

For I = 1 To 25

X = Int(Rnd * 25) + 1

N1 = X \ 5

N2 = X Mod 5 + 1

a(N1, N2) = I

Do

X = Int(Rnd * 5 * 5) + 1

If b(X) = 0 Then

a(N1, N2) = I

b(X) = 1

Exit Do

End If

Loop

Print X;

Print

Next I

Rating
• ?
Lv 5

Dim a(5, 5)

Dim b(122) As Integer

Dim X As Integer

Randomize

For i = 1 To 25

X = Int(Rnd * 25) + 1

N1 = X \ 5

N2 = X Mod 5 + 1

a(N1, N2) = i

Do

X = Int(Rnd * 5 * 5) + 1

If b(X) = 0 Then

a(N1, N2) = i

b(X) = 1

Exit Do

End If

Loop

Print X;

If i Mod 5 = 0 Then Print'==============多這一行就可以了================

Next i

但是這樣的話那個a陣列就形同虛設的(因為沒有完全填滿)

不考慮陣列的話......下面這個方法就可以

Dim b(25) As Integer

Dim X As Integer

Randomize

For i = 1 To 25

Do

X = Int(Rnd * 25 + 1)

If b(X) = 0 Then

b(X) = 1

Print X;

Exit Do

End If

Loop

If i Mod 5 = 0 Then Print

Next i

如果要陣列中的值也如同列印出來的一樣的話(單迴圈)

這是我的方法~參考一下

Dim a(5, 5) As Integer

Dim b(25) As Boolean

Dim N1, N2 As Integer

Dim i, j As Integer

Dim X As Integer

N1 = 1

N2 = 1

Randomize Timer

Do

X = Int(Rnd * 25 + 1)

If b(X) <> True Then

b(X) = True

a(N1, N2) = X

Print X;

N1 = N1 + 1

If N1 > 5 Then

N1 = 1

N2 = N2 + 1

Print

End If

End If

Loop Until N2 = 5

2005-09-29 23:40:38 補充：

為什麼是負面評價?

程式的哪邊有問題請提出來

大家一起討論~

突然給個負評價實在是........

2005-09-30 17:06:50 補充：

喵~我沒說是你 @@

我覺得說...既然點了負評

至少也要說說是哪邊不好

這樣我有改進的空間 ^^

Source(s): 經驗