1*2+2*3+3*4+.....n*(n+1)+....编写程序,计算前n项中偶数项的和,n取50.要求用循环做,本题是vb程序题

来源:百度知道 编辑:UC知道 时间:2024/05/31 16:33:54
请写下vb代码,要用循环做,谢谢大家

'建立一个command1

Dim n As Integer, i As Integer, total As Integer

Private Sub command1_Click()
Cls
n = InputBox("请输入n的值:", "输入", "5")
total = 0
For i = 1 To n
If i Mod 2 = 0 Then
total = total + i * (i + 1)
End If
Next i
Print "前"; n; "项中偶数项的和是:"; total
End Sub
已经运行过。

s=0
for i=2 to 50 step 2
s=s+i*(i+1)
next i
print s

Private Sub Form_Click()
Dim n As Integer
n = Val(InputBox("请输入求和的值"))
s = 0
For i = 1 To n
s = s + i * (i + 1)
Next i
Print "s="; s
End Sub