1、Private Function JS(n As Long) As DoubleIf n > 0 Then Dim i As Integer, t As Double t = 1 For i = 1 To n t = t * i Next JS = JS(n - 1) + tEnd IfEnd Function2、Private Sub XS()Msgbox JS(20)End Sub
阶乘一般是用递归法写函数的。