十分钟求帮助!计算机VB!!编写程序!求出e值! e=1+1⼀1!+1⼀2!+1⼀3!+1⼀4!

2024-12-04 11:47:15
推荐回答(1个)
回答1:

Private Sub Command1_Click()
Dim e As Single, t As Single, n As Integer '---------定义三个变量
e = 1: n = 0: t = 1 '---------------------------------对三个变量进行初始化
Do '-------------------------------------------------循环
n = n + 1 '-------------------------------------n为循环条件,从1,2,3...................
t = t / n '---------------------------------------计算1/1, 1/1*2 即1/n!的计算.
e = e + t '-------------------------------------得出结果 e=1+1/1!+1/2!+......+1/n!
Loop While t > 0.0000001 '--------------------循环结束条件,精确到第六位
Print e, n '- ------------------------------打印; e和n
End Sub