求质因子数 Vb

2024-12-15 21:23:13
推荐回答(2个)
回答1:

Option Explicit

Private Sub Command1_Click()
Dim n As Long
n = Val(Text1)
Text2 = FenJie(n)
End Sub

Private Function FenJie(n As Long) As String
Dim T As String, i As Long, k As Long
i = n
k = 2
Do While (k <= n)
If n Mod k = 0 Then
T = T & k & "*"
n = n / k
Else
k = k + 1
End If
Loop
FenJie = i & "=" & Left(T, Len(T) - 1)
End Function

回答2:

dim n as integer
n= inputbox("please input a integer")
dim m as integer
dim strtemp as string
dim i as integer
m=n
strtemp="";
do while(m>1)
for i = 2 to m
if (m mod i) =0 then
strtemp=strtemp + str(i) + "*"
m = m\i
exit for
end if
next i
loop
strtemp = left(strtemp,len(strtemp)-1)
print strtemp