大数的阶乘

2008-04-10 03:07:07来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

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

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:在弹出模态对话框(消息框)的同时设置他的位置

下一篇:监控网页中元素的事件