VB题:e=1+1⼀1!+1⼀2!+1⼀3!+...+1⼀n!

2024-12-04 11:23:33
推荐回答(5个)
回答1:

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分都这么难挣了。。。。

回答2:

'阶乘倒数函数
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 分,哈,哈,哈

回答3:

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

回答4:

VB/....额好遥远的记忆。。。唉学的C++都忘了,更别提c ,vb了。。。

回答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
分,哈,哈,哈