作业帮 > 数学 > 作业

用VB计算 S=1+1/2+1/4+1/7+1/11+1/16+1/22+1/29+…当i项值

来源:学生作业帮 编辑:神马作文网作业帮 分类:数学作业 时间:2024/11/15 20:17:44
用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 Su