VB6.0~~~请教。谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/05 09:59:12
编一个程序求两万以内的素数和怎么写啊?高手指点一下啊!!谢谢啦!!

Private Sub command1_click()
Dim i, j
For i = 1 To 20000
For j = 2 To 10
If i Mod j = 0 Then
a = a + 1
End If
Next j
If a = 0 Then
s = s + 1
End If
a = 0
Next i
Text1.Text = s
End Sub
S是素数个数
如果要逐个输出素数就改成
Private Sub command1_click()
Dim i, j
For i = 1 To 20000
For j = 2 To 10
If i Mod j = 0 Then
a = a + 1
End If
Next j
If a = 0 Then
print i
End If
a = 0
Next i
End Sub