Public Function factorial (intc as integer) as string
On Error goto myerr:
Dim INTA () as integer, intt () as integer, I as integer
Dim J as integer, Intr as integer
Redim INTA (20), intt (20)
If intc <2 then exit function
Intr = 20
INTA (0) = 1
For I = 2 to intc
For J = 0 to intr
Intt (j) = INTA (j) * I
Next J
J = 0
Do until j> intr
INTA (j) = intt (j) mod 10
If intt (j)> = 10 then intt (J + 1) = intt (J + 1) + intt (j)/10
J = J + 1
Loop
Next I
Do While true
J = J-1
If INTA (j)> 0 Then exit do
Loop
For J = J to 0 step-1
Factorial = factorial & INTA (j)
Next J
Exit Function
Myerr:
If err. Number = 9 then
Intr = intr + 20
Redim preserve INTA (intr)
Redim preserve intt (intr)
Resume
Else
Msgbox "unknow err:" & err. Description & ":" & err. Number, vbcritical + vbokonly
End if
End Function
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service