需要2个文本框text 和 2个按钮command (一个计算 一个清除)
Dim x, a, b, k As String
Private Sub Command1_Click()
a = Val(Text1.Text)
x = 2
If a <= 1 Or a > Int(a) Then
If a = 1 Then
Text2.Text = "它既不是质数,也不是合数"
Else
MsgBox "请您先输入数据", vbOKOnly + vbInformation, "友情提示"
End If
Else
Do While a / 2 = Int(a / 2) And a >= 4
If b = 0 Then
Text2.Text = Text2.Text & a & "=" & "2"
b = 1
Else
Text2.Text = Text2.Text & "*2"
End If
a = a / 2
k = a
Loop
Do While a > 1
For x = 3 To Sqr(a) Step 2
Do While a / x = Int(a / x) And a >= x * x
If b = 0 Then
Text2.Text = Text2.Text & x
b = 1
Else
Text2.Text = Text2.Text & "*" & x
End If
a = a / x
Loop
Next
k = a
a = 1
Loop
If b = 1 Then
Text2.Text = Text2.Text & "*" & k
Else
Text2.Text = "这是一个质数"
End If
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
拷贝于:http://zhidao.baidu.com/question/75883517.html?an=0&si=1