计算机编程求S=1+1/(1+2)+1/(1+2+3)+…
答案:1 悬赏:20 手机版
解决时间 2021-03-11 23:35
- 提问者网友:放下
- 2021-03-11 11:33
计算机编程求S=1+1/(1+2)+1/(1+2+3)+…
最佳答案
- 五星知识达人网友:枭雄戏美人
- 2021-03-11 12:02
VB?代码如下,VB6测试通过:
Private Sub Command1_Click()
Dim i As Integer, sum As Single, n As Integer
n = Val(Text1.Text)
For i = 1 To n
sum = sum + ds(i)
Next i
Label1.Caption = Str(sum)
End Sub
Function ds(n As Integer) As Single
Dim j As Integer, jsum As Integer
For j = 1 To n
jsum = jsum + j
Next j
ds = 1 / jsum
End Function
Private Sub Command1_Click()
Dim i As Integer, sum As Single, n As Integer
n = Val(Text1.Text)
For i = 1 To n
sum = sum + ds(i)
Next i
Label1.Caption = Str(sum)
End Sub
Function ds(n As Integer) As Single
Dim j As Integer, jsum As Integer
For j = 1 To n
jsum = jsum + j
Next j
ds = 1 / jsum
End Function
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯