用Visual Basic程序求S=1+(1+2)+(1+2+3)+(1+2+3+4)+···(1+2+3+···+1 10
2个回答
展开全部
这个很简单的,我把它加在了窗体的CLICK事件里了,你看下,已经测试过了,结果是正确的。希望对你有用。
Private Sub Form_click()
n = Val(InputBox("请输入项数N", "输入"))
s = 0: p = 0
For i = 1 To n
p = p + i
s = s + p
Next i
Print s
End Sub
Private Sub Form_click()
n = Val(InputBox("请输入项数N", "输入"))
s = 0: p = 0
For i = 1 To n
p = p + i
s = s + p
Next i
Print s
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Load()
'S=1+(1+2)+(1+2+3)+(1+2+3+4)+···(1+2+3+···+N
Dim i As Integer
Dim S As Double
Dim N As Integer
Dim A As Integer
N = 10
S = 0
Text1.Text = " i S A" + Chr(13) + Chr(10)
For i = 1 To N
S = S + i
A = A + S
Text1.Text = Text1.Text + " " + CStr(i) + " " + CStr(S) + " " + CStr(A) + Chr(13) + Chr(10)
Next i
End Sub
'S=1+(1+2)+(1+2+3)+(1+2+3+4)+···(1+2+3+···+N
Dim i As Integer
Dim S As Double
Dim N As Integer
Dim A As Integer
N = 10
S = 0
Text1.Text = " i S A" + Chr(13) + Chr(10)
For i = 1 To N
S = S + i
A = A + S
Text1.Text = Text1.Text + " " + CStr(i) + " " + CStr(S) + " " + CStr(A) + Chr(13) + Chr(10)
Next i
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询