试用VB程序语言写出主要程序段:求S=1!+2!+3!+……+99!的值

2024-12-18 16:47:37
推荐回答(3个)
回答1:

Private Sub Command1_Click()
Dim i As Integer, s As Double
For i = 1 To 99
s = s + fact(i)
Next i
Print "s=" & s
End Sub

Private Function fact(n As Integer) As Double
fact = 1
For i = 1 To n
fact = fact * i
Next i
End Function

回答2:

Function factor(n As Integer) As Double
If n = 1 Then
factor = 1
Else
factor = n * factor(n - 1)
End If
End Function
Private Sub Command1_Click()
Dim i As Integer
For i = 1 To 99
s = s + factor(i)
Next
Print s;
End Sub
我也在学VB。书上个给你找的,希望对你有帮忙呀

回答3:

Private Sub Command1_Click()
Dim S As Double, jc As Double
jc = 1
For i = 1 To 99
jc = jc * i
S = S + jc
Next
Print "S="; S
End Sub