用fact函数求阶乘求和的vb语言用过程法 1!+2!+3!+ +n! 调用fact函数求阶乘之和
Private Sub Command1_Click()
Dim a As Integer, I As Integer, Sum As Long
a = Val(Text1.Text)
For I = 1 To a
Sum = Sum + fact(I)
Next
Text2.Text = Sum
End Sub
Private Function fact(X As Integer)
Dim K As Integer, S As Long
S = 1
For K = 1 To X
S = S * K
Next
fact = S
End Function
(“%D&N)1.scanf半引号 2严重错误少,主要功能和应给予初始为0
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