• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

大数的阶乘

发布: 2007-5-25 09:21 | 作者: jennyvenus | 来源: 互联网 | 查看: 58次 | 进入软件测试论坛讨论

领测软件测试网 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

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/