编1-3+5-7+…+(-1)^n+1(2n-1)的VB代码
答案:2 悬赏:10 手机版
解决时间 2021-06-05 14:14
- 提问者网友:相思似海深
- 2021-06-04 22:35
编1-3+5-7+…+(-1)^n+1(2n-1)的VB代码
最佳答案
- 五星知识达人网友:从此江山别
- 2021-06-04 23:40
private function JiSuan(n as integer) as long
dim s as long=0
dim i as integer
for i=1 to n
s=s+-(-1)^i*(2*i-1)
next
return s
end function
全部回答
- 1楼网友:往事隔山水
- 2021-06-05 00:26
Private Sub Command1_Click()
Dim sum As Integer, k As Integer
n = CInt(InputBox("请输入n:"))
k = 1
sum = 0
For i = 1 To n
sum = sum + k * (2 * i - 1)
k = -k
Next i
MsgBox "sum = " & sum
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯