Today, I went around for a boring search and asked:
Who can provide detailed procedures for the 20 factorial in vbs?
The answer is as follows:Copy codeThe Code is as follows: function jx (x)
J = 1
For I = 2 to x
J = j * I
Next
Jx = j
End function
Msgbox jx (20)
Run the above program and output 2.43290200817664E + 18. Smiling, I once again proved my previous conclusion that most of my answers to questions on such websites are poor.
In fact, I have already written VBS's multiplication of large numbers in "accurately calculate the power of 2 with VBS". Just call it:Copy codeThe Code is as follows: 'author: Demon
'Website: http://demon.tw
'Email: 380401911@qq.com
Option Explicit
Function multiple (byVal x, byVal y)
Dim n, t, I, j, z, w ()
N = Len (x)-1
T = Len (y)-1
ReDim w (n + t + 1)
X = CStr (x): y = CStr (y)
For I = 0 To UBound (w)
W (I) = "0"
Next
For I = 0 To t
Dim c: c = 0
Dim uv: uv = 0
For j = 0 To n
Uv = (w (I + j)-"0") + c ++ _
(Mid (x, n-j + 1,1)-"0") * (Mid (y, t-I + 1,1)-"0 ")
W (I + j) = CStr (uv Mod 10 + "0 ")
C = uv \ 10
Next
W (I + n + 1) = CStr (uv \ 10 + "0 ")
Next
Z = Join (w ,"")
Z = StrReverse (z)
Do While Left (z, 1) = "0"
Z = Mid (z, 2)
Loop
Multiple = z
End Function
Function factorial (n)
Dim I, t: t = 1
For I = 1 To n
T = multiple (t, I)
Next
Factorial = t
End Function
Dim t: t = Timer
WScript. Echo factorial (100)
WScript. Echo Timer-t
In addition, dogfish also writes a vbs for the 1000 factorial:Copy codeThe Code is as follows: dim digits (2568)
Max_digit= 2568
Digits (max_digit) = 1
For d = 2 to 1000
For k = max_digit to ubound (digits)
Digits (k) = digits (k) * d
Next
K = ubound (digits)
While k> = max_digit
If digits (k)> 10 then
Digits (k-1) = digits (k-1) + fix (digits (k)/10)
Digits (k) = digits (k) mod 10
If K-1 <max_digit then
Max_digit = k-1
End if
End if
K = K-1
Wend
Next
'Convert the result into a string.
Str = ""
For I = max_digit to ubound (digits)
Str = str & digits (I)
Next
Msgbox str
However, people who can write such a program will not be bored to answer questions asked by sousearch.
Original article: http://demon.tw/programming/vbs-factorial.html