精華區beta Visual_Basic 關於我們 聯絡資訊
Public Sub ShowPrime() MsgBox "1到" & 100 & "之間的質數有:[" & EnumPrime(100) & "]", _ vbInformation End Sub Public Function IsPrime(ByVal number As Long) As Boolean If number <= 1 Then IsPrime = False: Exit Function If number = 2 Or number = 3 Or number = 5 Or number = 7 Then IsPrime = True: Exit Function End If Dim i As Long For i = 2 To Sqr(number) If number Mod i = 0 Then IsPrime = False: Exit Function Next IsPrime = True End Function Public Function EnumPrime(ByVal n As Long) As String Dim i As Long, count As Long, s As String For i = 1 To n If IsPrime(i) Then If s <> "" Then s = s & "," s = s & i End If Next EnumPrime = s End Function -- ▃▅▇▆▄ ▆▂▃ ` 逝去感如何能留住,半點遺留殊不易,██▅▇▄▃ ▇▃▂" . █████████▃i ▁▄▇ 更多悽悽慘慘的遭遇………██▆▃ █▅▆▃ˍ▄* ▂█▄▇▅▂. 我不知道,王~八~蛋~~! ▂▆███ █▄▃ 。fumizuki。Check。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.194.224.174