vb编程找10到100内的素数

来源:百度知道 编辑:UC知道 时间:2024/06/14 10:06:32

Private Sub Command1_Click()
Print "10---100之间的素数有:"
For i = 10 To 100
If Prime(i) = True Then Print i & ","
Next
End Sub
Private Function Prime(ByVal n As Long) As Integer
Dim K As Boolean, i As Integer
For i = 2 To Int(n / 2)
If n Mod i = 0 Then Prime = False: Exit Function
Next
Prime = True
End Function