vb编程:自然对数的底数e的值可由如下无穷级数计算:e=1+1/1!+1/2!+……+1/n!
问题描述:
vb编程:自然对数的底数e的值可由如下无穷级数计算:e=1+1/1!+1/2!+……+1/n!
使用for语句编写程序计算e的值,式中的n值可由用户输入.
答
Private Sub Form_Click()
Dim N As Integer, e As Single, I As Integer, J As Integer, Jc As Double
N = Int(Val(InputBox("计算的项数N=", "输入", 5)))
Jc = 1
e = 1
For I = 1 To N
Jc = Jc * I
e = e + 1 / Jc
Next
Print "e=1+1/1!+1/2!+……+1/"; N; "! = "; e
End Sub
已经运行过,有什么问题请留言.