用VB设计程序,求出1+1/3+1/5+1/7+......+1/(2*n-1)的值
本题共有三个变量,分别是n:整型(不是long),x和sum均为single,条件是:当想<0.00001时停止计算,并在文本框text1中输出结果,急求大神指教!!!条...
本题共有三个变量,分别是n:整型(不是long),x和sum均为single,条件是:当想<0.00001时停止计算,并在文本框text1中输出结果,急求大神指教!!!
条件是x<0.00001 展开
条件是x<0.00001 展开
3个回答
展开全部
Private Sub Form_Click()
Dim n As Integer
Dim x As Single
Dim sum As Single
sum = 0
x = 1
Do While 1 / x > 0.00001
x = 2 * x - 1
sum = sum + 1 / x
x = x + 1
Loop
Print x, sum
Text1.Text = sum
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim n As Long, x As Single, sum As Single
n = 0: x = 1: sum = 0
Do Until x < 0.00001
n = n + 1
x = 1 / (2 * n - 1)
sum = sum + x
Loop
Text1.Text = sum
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询