高分。VB高手请进。一道VB作业题

来源:百度知道 编辑:UC知道 时间:2024/06/19 15:21:26
函数 e^x 能用下面的方式表达
e^x.= 1+ x/(1!)+ x^2/(2!) + x^3/(3!)+ x^4/(4!) +………

因为这是一个无限增长的数列,我们需要确定我们要加多少个项。这个数列中的项会变得越来越少,当达到一定的精确度,e^x就能被确定

编程要求
使用一个main program 和两个 user-defined Function Subprogram

在main program中, 让读者输入x 的值 来计算ex.
在main program 中, 让读者输入这个数列中的末项最大值
在main program中, 输出ex 的值
使用一个user-define Funtion 来计算 ex
使用一个user-defined Function来计算阶乘,N!

我真的想不到该用什么逻辑去求出ex vb 该用的语法我都懂,可是我就是想不到那个逻辑
谢谢各位大侠
以上是中文翻译
可能不太准确
以下是英文原文
Program requirements:
- Use a main program and two user-defined Function subprograms.
- In the main program, prompt user in enter a value, x, to use in calculating ex.
- In the main program, prompt the user to enter a maximum value of the last term in the series (suggested value = 1 x 10-7).
- In the main program, output the answer (the calculated ex value) and calculate the e(x) using VBA built-in function and output that answer also (for compa

你那都编的什么乱七八糟的,我看了半天才理解,以下我帮你改的。。。还不如从新编一个来得快~~~
Private Sub Command1_Click() 'Main Program是一个按钮
Dim x As Integer, Lasttermlimit As Single, expx As Single
Dim expbuildinfunction As Single, answer As Single, count As Integer

x = InputBox("Please enter a value for x") '输入x
expbuildinfunction = Exp(x) '计算真实值e^x
Lasttermlimit = InputBox("Please enter a value for the last limit value") '用一个inputbox获取末项极限值,当末项小于此值时停止运算

count = 1
Do
expx = singleterm(x, count)

If expx < Lasttermlimit Then Exit Do '当单项小于末项极限值时退出循环
count = count + 1
answer = answer + expx
Loop
answer = answer + 1
MsgBox (" The calculated e^x value is " & answer & " The value of e^x in the VBA buildin function is " & expbuildinfunction)
End Sub

Function fact(ByVal count1 As Integer) As Single '计算阶乘
If count1 = 1 Then
fact