用fact函数求阶乘求和的vb语言用过程法 +2!+3!+ +n!调用fact函数求阶乘之和

来源:学生作业学帮网 编辑:学帮网 时间:2024/05/14 20:04:50

用fact函数求阶乘求和的vb语言用过程法 +2!+3!+ +n!调用fact函数求阶乘之和

Option Explicit
Dim s As Integer
Private Sub Command1_Click()
Text2.Text = Str(fact(Val(Text1.Text)))
s = 0
End Sub
Private Function fact(n As Integer) As Integer
Dim i As Integer,j As Integer
j = 1
fact = 0
For i = 1 To n
j = j * i
s = s + j
Next i
fact = s
End Function