怎么用VB来求Y=1-1/2+1/3-1/4+1/5-1…前30项之和。
答案:6 悬赏:20 手机版
解决时间 2021-04-20 19:15
- 提问者网友:棒棒糖
- 2021-04-20 13:19
怎么用VB来求Y=1-1/2+1/3-1/4+1/5-1…前30项之和。
最佳答案
- 五星知识达人网友:平生事
- 2021-04-20 14:39
Private Sub Command1_Click()
Dim sum1 As Long
Dim a, i, j As Integer
sum = 0
j = 1
For i = 1 To 30
sum = sum + j * 1 / i
j = j * -1
Next i
MsgBox sum
End Sub
Dim sum1 As Long
Dim a, i, j As Integer
sum = 0
j = 1
For i = 1 To 30
sum = sum + j * 1 / i
j = j * -1
Next i
MsgBox sum
End Sub
全部回答
- 1楼网友:底特律间谍
- 2021-04-20 18:25
For i = 1 To 30
If i Mod 2 = 0 Then
s = s - 1 / i
Else
s = s + 1 / i
End If
Next i
Print s
- 2楼网友:人類模型
- 2021-04-20 18:07
Private Sub Form_Load() MsgBox Sum(30) End Sub Function Sum(ByVal n As Integer) As Single
Dim i As Integer Sum = 0 For i = 1 To 30 Sum = Sum + (-1) ^ (i + 1) * (1 / i) Next End Function
- 3楼网友:不如潦草
- 2021-04-20 16:50
for i = 1 to 30
sum = sum+(-1)^(i+1)*1/i
next i
msgbox sum
- 4楼网友:枭雄戏美人
- 2021-04-20 16:15
Option Explicit
Const N = 30 '30项
Private Sub Form_Activate()
Dim i As Integer, s
For i = 1 To N
s = s + (-1) ^ (i - 1) / i
Next
MsgBox N & "项之和:" & Format(s, "0.00000000")
Unload Me
End Sub
- 5楼网友:有你哪都是故乡
- 2021-04-20 15:36
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim s As Single
j = -1
For i = 1 To 30 j = -1 * j
s = s + j * 1 / i
Next
Print s
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯