5*5的方格N1跟N2

我的成是碼~"~其中有一段

X = Int(Rnd * 25) + 1

N1 = X \ 5

N2 = X Mod 5 + 1

a(N1, N2) = I

這段好像寫錯的樣子執行的時候不會出現5*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;

Print

Next I

2 Answers

Rating
  • ?
    Lv 5
    2 decades ago
    Favorite Answer

    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): 經驗
  • 2 decades ago

    @@~我沒給負面頻價阿~是別人給的= =我也不知道是誰....

    2005-09-30 23:36:23 補充:

    恩恩@@~不過要說改進空間...就是......如果程式碼後面能多加點註解比較好~"~太新手會看不懂....

Still have questions? Get your answers by asking now.