下面是一个VB代码求100~200之间的全部素数的代码:
Public Function IsSushu(ByVal pa As Integer) As Boolean
Dim pb As Integer = pa - 1
Dim res As Boolean = True
For i = 2 To pb
If pa Mod i = 0 Then
res = False
Exit For
End If
Next i
Return res
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String
str = ""
For i = 100 To 200
If IsSushu(i) Then
str = str & i & " "
End If
Next
MsgBox(str)
End Sub
运行结果: