用VB编写函数过程,计算s=1+1⼀2+1⼀3+…+1⼀100。运行程序时,单击窗体,输出上述计算结果的值。

2024-12-26 06:26:53
推荐回答(3个)
回答1:

private sub Form_Click()
dim i as long
dim s as currency
s=1
for i=2 to 100
s=s+(1/i)
next i
msgbox s
end sub
'这个程序会弹出精确到4位小数的结果,如果需要更高精度的,可以试着把currency换成double。

回答2:

Private Sub Command1_click()
Dim n As Integer
n = 100
Print f(n)
End Sub

Function f(n)
For i = 1 To n
f = f + 1 / i
Next i

End Function

回答3:

s=0
for i=1 to 100
s=s+1/i
next
msgbox s