回覆列表
  • 1 # 小紅的甜心

    定義一個全域性變數的陣列:

    dim a(10) as integer

    隨機產生10個兩位的素數,素數各不相同:

    Dim a(10), x As Integer

    Dim str As String = ""

    Dim di As Boolean = True

    Dim n As Integer

    Dim sd As

    For i = 1 To 10

    Do

    Do

    Randomize()

    n = Int(Rnd() * 100 + 10)

    Loop Until IsSushu(n)

    If i > 1 Then

    For x = 1 To i - 1

    If a(x) = n Then

    di = False

    End If

    Next

    End If

    Loop Until di = True

    a(i) = n

    "str = str & a(i) & " "

    Next

    隨機數升序排序:

    For i = 1 To 10

    For j = 1 To 10 - i

    If a(j) > a(j + 1) Then

    x = a(j + 1)

    a(j + 1) = a(j)

    a(j) = x

    End If

    Next j

    Next i

    For i = 1 To 10

    str = str & a(i) & " "

    Next

    將升序的陣列寫入檔案:

    Dim file As New System.IO.StreamWriter("data1.txt")

    file.WriteLine(str)

    file.Close()

    讀取檔案,並寫入陣列及降序排序:

    Dim file As New System.IO.StreamReader("data1.txt")

    Dim words As String = file.ReadToEnd()

    file.Close()

    Dim b() As String

    Dim temp As Integer

    Dim str1 As String

    str1 = ""

    b = Split(words, " ")

    Dim c() As Integer

    Dim l As Integer

    l = UBound(b)

    ReDim c(l)

    For i = 1 To l

    c(i) = Val(b(i - 1))

    Next

    For i = 1 To l

    For j = 1 To l - i

    If c(j) < c(j + 1) Then

    temp = c(j + 1)

    c(j + 1) = c(j)

    c(j) = temp

    End If

    Next j

    Next i

    For i = 1 To l

    str1 = str1 & c(i) & " "

    Next

    MsgBox(str1)

  • 2 # 夢夢月神

    我想在別的小區買個2手停車位,宣告,我不是這小區的業主,如果這個車位我跟那小區業主交易22萬,那我還要交多少稅收,我要詳細解釋

  • 中秋節和大豐收的關聯?
  • 如果一個男生對你忽冷忽熱代表著什麼?