大数的阶乘

发表于:2007-07-01来源:作者:点击数: 标签:
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 F
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

原文转自:http://www.ltesting.net