用VB计算 S=1+1/2+1/4+1/7+1/11+1/16+1/22+1/29+…当i项值
问题描述:
用VB计算 S=1+1/2+1/4+1/7+1/11+1/16+1/22+1/29+…当i项值
答
Private Sub Command1_Click() Dim m As Integer,n As Integer,s,result 'm为分母变量,n为位置变量,s为数值变量,result为和的变量 m = 1:n = 0:s = 1 / m:result = 0 + 1 / 1 Do While s >= 10 ^ -4 n = n + 1 m = m + n s = 1 / m result = result + s Loop MsgBox "S=1+1/2+1/4+1/7+1/11+1/16+1/22+1/29+… " & vbCrLf & "运算结果为:" & result,vbOKOnly,"运算结果" End Sub