CSDN博客

img jennyvenus

大数的阶乘

发表于2003/1/15 9:21:00  926人阅读

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
0 0

相关博文

我的热门文章

img
取 消
img