另外你应该先弄清循环语句的作用
下面是修改后的程序
Private Sub Command1_Click()
Dim a As Integer
Dim k As Integer
Dim i As Integer
a = Text1.Text
If a = 1 Then
Label2.Caption = "此数既不是质数,也不是合数"
End If
If a = 2 Then
Label2.Caption = "此数是质数"
End If
If a >2 Then
If i <a Then
For i = 2 To a - 1 Step 1
n = a Mod i
If n = 0 Then
Label2.Caption = "此数不是质数"
Exit Sub
End If
Next i
End If
Label2.Caption = "此数是质数"
End If
End Sub
Private Function IsPrime(ByVal n As Integer) As BooleanDim pb As Integer
pb = n - 1
IsPrime = True
For i = 2 To pb
If n Mod i = 0 Then
IsPrime = False
Exit For
End If
Next i
End Function
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)