VB程序设计 计算S=1+1/2+1/4+1/7+1/11+1/16+1/22+……,要求加数不小于0.00001并显示S及加数的项目数.
问题描述:
VB程序设计 计算S=1+1/2+1/4+1/7+1/11+1/16+1/22+……,要求加数不小于0.00001并显示S及加数的项目数.
答
Private Sub Command1_Click()
Dim s As Double
Dim a As Long,n As Long
n = 1
a = 1
s = s + 1 / a
Do Until 1 / a a = a + n
s = s + 1 / a
n = n + 1
Loop
Print "s=" & s
Print "共加了" & n & "项"
End Sub