vb试题编程计算1-1/2+1/3-1/4+...+1/99-1/100
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
展开全部
1:
Dim i As Integer
Dim s As Double
Dim s0 As Double
For i = 1 To 100
s0 = 1 / i
If i Mod 2 = 0 Then s0 = s0 * (-1)
s = s + s0
Next
Print s
2:
Dim i As Integer
Dim s As Double
For i = 1 To 100 Step 2
s = s + 1 / i - 1 / (i + 1)
Next
Print s
3:
Dim i As Integer
Dim s As Double
i = 1
Do Until i >= 100
s = s + 1 / i - 1 / (i + 1)
i = i + 2
Loop
Print s
4:
Dim i As Integer
Dim s As Double
For i = 1 To 100
Select Case i Mod 2
Case 0
s = s - 1 / i
Case 1
s = s + 1 / i
End Select
Next
Print s
Dim i As Integer
Dim s As Double
Dim s0 As Double
For i = 1 To 100
s0 = 1 / i
If i Mod 2 = 0 Then s0 = s0 * (-1)
s = s + s0
Next
Print s
2:
Dim i As Integer
Dim s As Double
For i = 1 To 100 Step 2
s = s + 1 / i - 1 / (i + 1)
Next
Print s
3:
Dim i As Integer
Dim s As Double
i = 1
Do Until i >= 100
s = s + 1 / i - 1 / (i + 1)
i = i + 2
Loop
Print s
4:
Dim i As Integer
Dim s As Double
For i = 1 To 100
Select Case i Mod 2
Case 0
s = s - 1 / i
Case 1
s = s + 1 / i
End Select
Next
Print s
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询