VB题:e=1+1/1!+1/2!+1/3!+...+1/n!
根据下列公式计算自然数e的近似值,要求计算到最后一项小于0.0001为止。e=1+1/1!+1/2!+1/3!+...+1/n!用WHILE。。。WEND请按要求答题,谢...
根据下列公式计算自然数e的近似值,要求计算到最后一项小于0.0001为止。
e=1+1/1!+1/2!+1/3!+...+1/n!
用WHILE。。。WEND
请按要求答题,谢谢 展开
e=1+1/1!+1/2!+1/3!+...+1/n!
用WHILE。。。WEND
请按要求答题,谢谢 展开
展开全部
Private Sub Command1_Click()
Dim iCount As Long
Dim N As Long
Dim eRet As Double
N = InputBox("输入n值")
If N > 0 And IsNumeric(N) Then
For iCount = 1 To N
eRet = eRet + 1 / FunforM(iCount)
Next
Else
MsgBox ("N小于零或非数字")
Exit Sub
End If
MsgBox CStr(eRet)
End Sub
Private Function FunforM(ByVal I As Long)
If (I > 1) Then
FunforM = I * FunforM(I - 1)
Else
FunforM = 1
End If
End Function
现在5分都这么难挣了。。。。
Dim iCount As Long
Dim N As Long
Dim eRet As Double
N = InputBox("输入n值")
If N > 0 And IsNumeric(N) Then
For iCount = 1 To N
eRet = eRet + 1 / FunforM(iCount)
Next
Else
MsgBox ("N小于零或非数字")
Exit Sub
End If
MsgBox CStr(eRet)
End Sub
Private Function FunforM(ByVal I As Long)
If (I > 1) Then
FunforM = I * FunforM(I - 1)
Else
FunforM = 1
End If
End Function
现在5分都这么难挣了。。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'阶乘倒数函数
private function JcDaoShu(byval X as long) as double
dim vVal as double
dim I as long
X = iif(X < 1, 1, X) '容错
vVal = 1.0
if X > 1
for i=1 to X
vVal = vVal / i
next i
Endif
JcDaoShu=vVal '返回
end fucntion
'主过程
dim e as double
dim de as dounle
dim N as long
N=1
e=1
de=JcDaoShu(N) '求阶乘的倒数
do until de<0.0001 'Until比While...Wend效率高,故用此
e=e+de
N=N + 1
de=JcDaoShu(N)
Loop
msgbox "自然对数 e==" & Val(e)
'主过程结束。接分了 50 分,哈,哈,哈
private function JcDaoShu(byval X as long) as double
dim vVal as double
dim I as long
X = iif(X < 1, 1, X) '容错
vVal = 1.0
if X > 1
for i=1 to X
vVal = vVal / i
next i
Endif
JcDaoShu=vVal '返回
end fucntion
'主过程
dim e as double
dim de as dounle
dim N as long
N=1
e=1
de=JcDaoShu(N) '求阶乘的倒数
do until de<0.0001 'Until比While...Wend效率高,故用此
e=e+de
N=N + 1
de=JcDaoShu(N)
Loop
msgbox "自然对数 e==" & Val(e)
'主过程结束。接分了 50 分,哈,哈,哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim n As Integer
Dim x As Integer
Dim y As Double
Dim e As Double
n = 1:x = 1:y = 1:e = 1
While n <= 100
While x <= n
y = y * x
x = x + 1
Wend
e = e + 1 / y
n = n + 1
Wend
Print "e=";e
End Sub
Dim n As Integer
Dim x As Integer
Dim y As Double
Dim e As Double
n = 1:x = 1:y = 1:e = 1
While n <= 100
While x <= n
y = y * x
x = x + 1
Wend
e = e + 1 / y
n = n + 1
Wend
Print "e=";e
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
VB/....额好遥远的记忆。。。唉学的C++都忘了,更别提c ,vb了。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'阶乘倒数函数
private
function
JcDaoShu(byval
X
as
long)
as
double
dim
vVal
as
double
dim
I
as
long
X
=
iif(X
<
1,
1,
X)
'容错
vVal
=
1.0
if
X
>
1
for
i=1
to
X
vVal
=
vVal
/
i
next
i
Endif
JcDaoShu=vVal
'返回
end
fucntion
'主过程
dim
e
as
double
dim
de
as
dounle
dim
N
as
long
N=1
e=1
de=JcDaoShu(N)
'求阶乘的倒数
do
until
de<0.0001
'Until比While...Wend效率高,故用此
e=e+de
N=N
+
1
de=JcDaoShu(N)
Loop
msgbox
"自然对数
e=="
&
Val(e)
'主过程结束。接分了
50
分,哈,哈,哈
private
function
JcDaoShu(byval
X
as
long)
as
double
dim
vVal
as
double
dim
I
as
long
X
=
iif(X
<
1,
1,
X)
'容错
vVal
=
1.0
if
X
>
1
for
i=1
to
X
vVal
=
vVal
/
i
next
i
Endif
JcDaoShu=vVal
'返回
end
fucntion
'主过程
dim
e
as
double
dim
de
as
dounle
dim
N
as
long
N=1
e=1
de=JcDaoShu(N)
'求阶乘的倒数
do
until
de<0.0001
'Until比While...Wend效率高,故用此
e=e+de
N=N
+
1
de=JcDaoShu(N)
Loop
msgbox
"自然对数
e=="
&
Val(e)
'主过程结束。接分了
50
分,哈,哈,哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询