The implementation code to calculate the factorial of 100 exactly with the VBS _VBS

Source: Internet
Author: User
Today, the boring stroll a search to ask, to find such a problem:

Who can provide a detailed procedure for the factorial of 20 in the VBS

Here are some answers to this:
Copy Code code 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. Laughing without words, once again proved my previous conclusion, in this site to answer questions, most of the level is not very much.

In fact, I have already written the large multiplication of VBS by using the 2 100-second square of the VBS, so call it:
Copy Code code 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 wrote a VBS that asks for 1000 factorial:
Copy Code code 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
' Turn the results into strings.
str = ""
For I=max_digit to UBound (digits)
str = str & digits (i)
Next
MsgBox Str

However, the person who can write such a program will not be bored to answer the question of search and ask.
Original: http://demon.tw/programming/vbs-factorial.html

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.