对屈原投江的看法:vb素数100200个数

来源:百度文库 编辑:中科新闻网 时间:2024/05/03 07:03:07
Private Sub Command1_Click()
Dim m, n, count As Integer
Dim p As Boolean

For m = 101 To 199 Step 2
p = False
For n = 2 To Int(m / 2)
If m Mod n = 0 Then Exit For
If n = Int(m / 2) Then p = True
Next n
If p = True Then count = count + 1
Next m
Print count
End Sub

怎么了?
求100~200间的素数
在我机子上运行是21呀

你想提的是什么问题??
21是100~200间的素数的个数.如果想要打印素数的话,可以加一个字符串:
Private Sub Command1_Click()
Dim m, n, count As Integer
Dim p As Boolean
Dim Result As String
For m = 101 To 199 Step 2
p = False
For n = 2 To Int(m / 2)
If m Mod n = 0 Then Exit For
If n = Int(m / 2) Then p = True
Next n
If p = True Then
Result = Result & " " & m
count = count + 1
End If
Next m
MsgBox Result, , count & "个"
End Sub