Private Function prime(n As Integer) As Boolean '返回值=True是素数,False不是素数
Dim k As Integer
prime = True
For k = 2 To n - 1
If (n Mod k) = 0 Then prime = False: Exit For
Next k
End Function
Private Sub Command1_Click()
Dim i As Integer,j as integer
For i = 2 To 100
If prime(i) Then
Print Format(i, "@@@@@");
j = j + 1
If j = 10 Then j = 0: Print
End If
Next
End Sub
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
For i = 2 To 100
If sushu(i) Then Print i
Next
End Sub
Function sushu(n As Integer) As Boolean
Dim i As Integer
sushu = True
For i = 2 To n - 1
If n / i = n \ i Then
sushu = False
Exit Function
End If
Next
End Function
10个一行你自己修改一下