在VB6.0中,求1!+3!+5!+7!+9!+....+n!阶乘的和,n利用InpuBos输入。

来源:百度知道 编辑:UC知道 时间:2024/07/08 00:17:22
我想知道在VB6.0中用双循环编辑的程序代码!多谢!!考试需要!
其中有要用到for next sum step
以上2个答案有误啊!!

已改:
Private Sub Command1_Click()
Dim n, i, k, s, sum
sum = 0

n = CInt(InputBox("Please input a value", ""))
For i = 1 To n Step 2
s = 1
For k = 1 To i Step 1
s = s * k
Next k
MsgBox s
sum = sum + s
Next i
MsgBox sum
End Sub

Private Sub Command1_Click()
x = InputBox("shu ru shuju", "nihao")
s = Fac(Val(x))
Print s
End Sub

Public Function Fac(Num As Integer) As Double
If Num = 1 Then
Fac = 1
Else
Fac = Fac(Num - 1) * Num
End If
End Function