当前位置:编程学习 > VB >>

vb编程求助

vb编程求助,编写收敛数列
1-3/(2的阶乘)+5/(3的阶乘)-...(精度0.00001),本人我目前学的比较浅,用For或者do/loop
追问:来自手机问问看不懂,能稍微解释下吗?
答案:代码:

Private Sub Command1_Click()
   Dim i As Integer, sum As Double, temp As Double
   i = 1
   sum = 0#
   temp = 0#
   Do
      temp = (-1) ^ (i - 1) * (2 * i - 1) / fun(i)
      If Abs(temp) < 0.00001 Then Exit Do
      sum = sum + temp
      i = i + 1
   Loop
   Print "该数列的值为:" + Str(sum)
End Sub

Function fun(n As Integer) As Long
   Dim i As Integer, sum As Long
   sum = 1
   For i = 1 To n
      sum = sum * i
   Next i
   fun = sum
End Function


 图:

 

Private Sub Command1_Click()
i = 0
j = 1
t = -1
n = InputBox("请输入n的值", "提示")
For i = 1 To n
i = i + 1
j = j * i
t = -t
a = t * i / j
s = s + a
Next i
Cls
Print s
End Sub

Private Sub Command1_Click()
Dim i, j, n As Integer

Dim s, t As Double

n = InputBox("请输入一个正在整数", 0)

s = 0

For i = 1 To n

    t = 1

    For j = 1 To n

        t = t * j

    Next

    t = (2 * i - 1) / t

    s = s + (-1) ^ (i - 1) * t

Next

s = Val(Format(s, "0.00000"))

End Sub

上一个:vb编程问题
下一个:vb编程开发

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,