1*2*3+2*3*4+3*4*5+.....n*(n+1)*(n+2)+...计算输出下面级数前n项(n=20)的部分和,

要求用循环做,写完成的vb代码,谢谢
2024-11-05 18:33:14
推荐回答(4个)
回答1:

int sum = 0;
for(int n = 1 ; n < = 20 ; n++)
{
sum += n * (n + 1) * (n +2);
}

伪代码,转成其他的也差不多

回答2:

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

回答3:

n=20
s=0
for i=1 to n
s=s+i*(i+1)*(i+2)
next i
print s

回答4:

Private Sub Command1_Click()
Dim n%, i%, y%, a%
a = 0
y = 1
n = Val(text1.Text)
For i = 1 To n
a = a + 1
y = y * a
Next i
End Sub