虽然回答这个问题会影响我的采纳率,但实在忍不住了,我还是要说两句。
为什么要integer而不是Long?
9!是362880,已经超出Integer的数值范围了,既然N是让别人输的,总不能跟人说“你只能输入1、2、3,输入4的话会溢出”吧?
这个题目本身很简单,加上这些限制条件就弱智了(我是指题目本身)。
Private Sub Command1_Click()
Dim N As Integer, S As Integer, i As Integer, j As Integer
Dim jj As Integer, hh As Integer
jj = 1
Do
N = Val(InputBox("请输入一个小于5的整数", "", 4))
Loop While N >= 5
For i = 1 To 2 * N - 1 Step 2
For j = 2 To i
jj = jj * j
Next
hh = hh + jj
jj = 1
Next
MsgBox hh
End Sub
Function S1(ByVal a As integer) As integer
For i = 1 To a
S1 = S1 * i
Next i
End Function
Function S(ByVal a As integer) As integer
For i = 1 To 2 * a - 1 Step 2
S = S + S1(i)
Next i
End Function
可否?