用VB写设计程序代码,求:s=1+(1+2)+(1+2+3)+……+(1+2+3+……+n)的值。 要求用DO循环
用VB写设计程序代码,求:s=1+(1+2)+(1+2+3)+……+(1+2+3+……+n)的值。 要求用DO循环
日期:2012-04-07 18:12:18 人气:2
'在窗体放一个按钮
Private Sub Command1_Click()
Dim n As Long, i As Long, sum As Double, sum0 As Double
n = Val(InputBox("输入一个正整数"))
Do While i <= n
sum0 = sum0 + i
sum = sum + sum0
i = i + 1
Loop
MsgBox "计算结果:" & sum
End Sub