求助 vb中 单击计算按钮出现1!+2!+3!....+20!的值 哪出错了
PrivateSubCommand1_Click()DimSAsDoubleDimSumAsDoubleDimIAsInteger,JAsIntegerSum=0ForI...
Private Sub Command1_Click()
Dim S As Double
Dim Sum As Double
Dim I As Integer, J As Integer
Sum = 0
For I = 1 To 20
'**********found************* '请不要删除该行'
S = 1
'**********found************* '请不要删除该行'
For J = 1 To 20
S = S * J
Next J
Sum = Sum + S
Next I
Text1.Text = Str(Sum)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub 展开
Dim S As Double
Dim Sum As Double
Dim I As Integer, J As Integer
Sum = 0
For I = 1 To 20
'**********found************* '请不要删除该行'
S = 1
'**********found************* '请不要删除该行'
For J = 1 To 20
S = S * J
Next J
Sum = Sum + S
Next I
Text1.Text = Str(Sum)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub 展开
2个回答
展开全部
For J = 1 To 20 这句错误,应改成For J = 1 To I ,否则每次I循环求得的S均为20!/I!而不是I!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim S As Double
Dim Sum As Double
Dim I As Integer, J As Integer
Sum = 0
For I = 1 To 20
'**********found************* '请不要删除该行'
S = 1
'**********found************* '请不要删除该行'
For J = 1 To 20--------------------------------------------这里,内循环是算1-20的阶乘,所以循环终值要改变,应为 for j=1 to i
------------------------------------------------------------------------------------------
S = S * J
Next J
Sum = Sum + S
Next I
Text1.Text = Str(Sum)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
Dim S As Double
Dim Sum As Double
Dim I As Integer, J As Integer
Sum = 0
For I = 1 To 20
'**********found************* '请不要删除该行'
S = 1
'**********found************* '请不要删除该行'
For J = 1 To 20--------------------------------------------这里,内循环是算1-20的阶乘,所以循环终值要改变,应为 for j=1 to i
------------------------------------------------------------------------------------------
S = S * J
Next J
Sum = Sum + S
Next I
Text1.Text = Str(Sum)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询