Dim yes As Boolean
Private Sub Command1_Click()
Randomize
s = 0
For i = 1 To 10
x = Int(90 * Rnd) + 10
Print x;
ss x
If yes Then s = s + x
Next i
Print "其中素数的总和="; s
End Sub
Private Sub ss(ByVal x As Integer)
yes = True
For j = 2 To Sqr(x)
If x Mod j = 0 Then yes = False: Exit For
Next j
End Sub
Public Function IsPrime(ByVal x As Integer) As Boolean
Dim i As Integer
IsPrime = True
For i=2 To x-1
If (x Mod i) = 0 Then
IsPrime = False
Exit Function
End If
Next
End Function
Private Sub Command1_Click()
Dim a As Integer, r As Integer, s As Integer
s = 0
For a=1 To 10
r = Int(90 * Rnd + 10)
If IsPrime(r) Then s = s + r
Next
Print r
End Sub