Private Sub Command1_Click()
n = Val(Text2.Text)
For i = 2 To n
Dim flag As Boolean
flag = True
For j = 2 To i - 1
If i Mod j = 0 Then
flag = False
Exit For
End If
Next j
If flag Then Text1.Text = Text1.Text & i & " "
Next i
End Sub
Private Sub Form_Load()
Command1.Caption = “???”
Text1.Text = “”
Label1.Caption = “???”
Text2.Text = “”
End Sub
定义flag要在第一个循环内,保证每一个数初始的flag都是true
VB中求素数
最新推荐文章于 2024-06-30 12:14:57 发布