VB疑难,一道很难的题

来源:百度知道 编辑:UC知道 时间:2024/05/04 20:03:14
在一个文本框中输入一个整数,在另一个文本框中显示这个数是否为素数。素数就是只能被1和他本身整除的数~~~~~~~~帮帮忙用VB编程,过程写出来~~~

Private Sub Form_Load()
Text1.Text = 17
End Sub
Private Sub Text1_Change()
Dim S As Long, I As Long
S = Val(Text1.Text)
If S < 2 Or Int(S) <> S Then Text2.Text = S & " 输入错误": Exit Sub
For I = 2 To S ^ 0.5
If S Mod I = 0 Then Text2.Text = S & " 不是素数": Exit Sub
Next
Text2.Text = S & " 是素数"
End Sub

Private Sub Text1_Change()
n = Val(Text1)
For i = 2 To Sqr(n)
If n / i = n \ i Then Exit For
Next
If n > 2 Then

If i > Sqr(n) Then
Text2 = n & "是素数"
Else
Text2 = n & "不是素数"
End If
Else
Text2 = ""
End If

End Sub

Public Function Issushu(x As Long) As Boolean
Dim chushu As Long
Dim sqrx As Long
sqrx = Sqr(x)
For chushu = 2 To sqrx
If x Mod chushu = 0 Then GoTo Yes
Next
Issu