100到1000内所有素数的平均数=524.944055944056
Private Function prime(ByVal n As Long) As Boolean '返回值=True是素数,False不是素数
Dim k As Long
If n < 2 Then
prime = False
Else
prime = True
For k = 2 To n - 1
If (n Mod k) = 0 Then prime = False:Exit For
Next k
End If
End Function
Private Sub Command1_Click()
Dim i,sum,cnt
For i = 100 To 1000
If prime(i) Then sum = sum + i:cnt=cnt+1
Next
print "100到1000内所有素数的平均数=" & cstr(sum/cnt)
End Su