在vb中。求100到200间的全部质数,质数个数显示在窗体上,

题目后面还有.质数从小到大依次写入顺序文件c:╲data.txt
2024年12月05日 13:36
有2个网友回答
网友(1):

Private Sub cmdCommand1_Click()
Dim i As Integer, j As Integer, num As Integer, Str As String, b As Boolean
For i = 101 To 199
b = True
For j = 2 To Sqr(i)
If i Mod j = 0 Then
b = False
Exit For
End If
Next
If b Then
num = num + 1
Str = Str & " " & i
End If
Next
Debug.Print Str
Print "质数个数: " & num
End Sub

网友(2):

可以看看我的文章:

http://hi.baidu.com/syx54/item/5eabf5dc8ccc2c1fd80e441e