危险废物许可证难办吗:vb问题,关于判别素数的

来源:百度文库 编辑:神马品牌网 时间:2024/05/05 12:04:01
Option Explicit
Dim i As Integer
Dim x As Integer

Private Sub c1_Click()
x = Val(t1.Text)
For i = 2 To x \ 2
If x Mod i = 0 Then Exit For
Next
If i = x \ 2 + 1 Then
MsgBox Str(x) + "是素数!"
Else
MsgBox Str(x) + "不是素数!"
End If
End Sub

Private Sub c2_Click()
Unload Me
End Sub

Private Sub c3_Click()
t1.Text = ""
t1.SetFocus
End Sub
能给我把这上面的关键语句一一解释一下吗

就是输入一个数x,然后判断
从2到x/2中是否存在一个数使得x除以它余数为0,如果有则这个数不是素数,没则是

Option Explicit 表示变量必须定义
If x Mod i = 0 Then Exit For 能整除则退出循环