欧美一区二区三区,国内熟女精品熟女A片视频小说,日本av网,小鲜肉男男GAY做受XXX网站

隨機產生10個兩位數的素數

榮姿康2年前12瀏覽0評論

隨機產生10個兩位數的素數?

定義一個全局變量的數組:

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)

java生成個隨機數組,隨機產生10個兩位數的素數