Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j, n As Integer
n = 0
For i = 2 To 1000
For j = 2 To i - 1
If i Mod j = 0 Then Exit For
Next
If j = i Then n += 1
Next
MsgBox("1-1000的素数的个数:" & n)
End Sub
End Class
追问等我下晚自习 回去试试
我忘了 里面对应的还有个进度条
进度条的话怎么用??
追答 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j, n As Integer
ProgressBar1.Minimum = 2
ProgressBar1.Maximum = 1000
n = 0
For i = 2 To 1000
For j = 2 To i - 1
If i Mod j = 0 Then Exit For
Next
If j = i Then n += 1
ProgressBar1.Value = i
Next
MsgBox("1-1000的素数的个数:" & n)
End Sub
追问不起作用呢
好了