Option Explicit
Private Sub Command1_Click()
Dim N%, i%
N = Text1
Label1 = Text1 & "=1"
Do
Call mini(N, i)
N = N / i: Label1 = Label1 & "*" & Str(i)
Loop While N > 2
End Sub
Private Sub mini(N%, i%)'求最小的质数。
For i = 2 To N
If N Mod i = 0 Then Exit For
Next i
End Sub
递归:
Private Sub getA(N As Integer)
If N <= 3 Then
Text1.Text = Text1.Text & "*" & N
Else
For i = 2 To N / 2
If N Mod i = 0 Then
N = N / i
Text1.Text = Text1.Text & "*" & i
Exit For
End If
Next i
getA (N)
End If
End Sub
如下调用:
Text1.Text = "36 = 1"
getA 36