以vb程序表达式1^2-2^2+3^2-4^2+…+(N-1)^2-N^2

2024-12-17 18:35:50
推荐回答(4个)
回答1:

Private Sub Command1_Click()
Dim n As Long, sum As Double
n = Val(InputBox("n=?"))
For i = 1 To n
sum = sum + (-1) ^ (i - 1) * i ^ 2
Next i
MsgBox "所求的和为:" & sum
End Sub

回答2:

Private Sub Command1_Click()
Dim n As Single, s As Double
n = Val(InputBox("n=?"))
For i = 1 To n
s = s + (-1) ^ (i - 1) * i ^ 2
Next i
print "和为:" & s
End Sub

回答3:

看不明白

回答4:

哇哇