求助,vb编程题目两题,能回答任何一题我都给分! 20
第一题:输入n和x(x的绝对值必须小于1)后,计算并显示下列表达式的值:1-x/2+x^2/3-x^3/4……+(-x)^(n-1)/n第二题:用近似公式求自然对数的底数...
第一题:输入n和x(x的绝对值必须小于1)后,计算并显示下列表达式的值:1-x/2+x^2/3-x^3/4……+(-x)^(n-1)/n
第二题:用近似公式求自然对数的底数e的值,直到前后两项的差小于10^(-4)为止。e=1+1/1!+1/2!+1/3!+……+1/n! 第二题要求用一重do循环实现,不要用数组
求计算机高手来解答下,分不多,但已经把我有的都给了! 展开
第二题:用近似公式求自然对数的底数e的值,直到前后两项的差小于10^(-4)为止。e=1+1/1!+1/2!+1/3!+……+1/n! 第二题要求用一重do循环实现,不要用数组
求计算机高手来解答下,分不多,但已经把我有的都给了! 展开
3个回答
展开全部
第一题:
计算函数:
Private Function JS(n As Long, x As Double) As Double
Dim mResult As Double
Dim i As Long
mResult = 0
For i = 0 To n - 1
mResult = mResult + ((-x) ^ i) / (i + 1)
Next
JS = mResult
End Function
第二题:
Private Sub Form_Click()
Dim i As Integer
Dim s, f As Double
i = 1
f = 1
s = 1
Do While (1 / f) > 10 ^ (-4)
f = f * i
s = s + 1 / f
i = i + 1
Loop
Print "e=" & Val(s)
End Sub
计算函数:
Private Function JS(n As Long, x As Double) As Double
Dim mResult As Double
Dim i As Long
mResult = 0
For i = 0 To n - 1
mResult = mResult + ((-x) ^ i) / (i + 1)
Next
JS = mResult
End Function
第二题:
Private Sub Form_Click()
Dim i As Integer
Dim s, f As Double
i = 1
f = 1
s = 1
Do While (1 / f) > 10 ^ (-4)
f = f * i
s = s + 1 / f
i = i + 1
Loop
Print "e=" & Val(s)
End Sub
展开全部
第一题:
运行条件:form1上面有3个控件,文本框text1,内容代表n,文本框text2,内容代表x,按钮command1,执行计算
Option Explicit
Private Sub Command1_Click()
MsgBox cal(Me.Text1, Me.Text2)
End Sub
Function cal(ByVal n As Integer, ByVal x As Single) As Single
Dim i As Integer
Dim result As Single
If Abs(x) >= 1 Then
cal = 0
End If
result = 0
For i = 0 To n - 1
result = result + ((-x) ^ i) / (i + 1)
Next
cal = result
End Function
运行条件:form1上面有3个控件,文本框text1,内容代表n,文本框text2,内容代表x,按钮command1,执行计算
Option Explicit
Private Sub Command1_Click()
MsgBox cal(Me.Text1, Me.Text2)
End Sub
Function cal(ByVal n As Integer, ByVal x As Single) As Single
Dim i As Integer
Dim result As Single
If Abs(x) >= 1 Then
cal = 0
End If
result = 0
For i = 0 To n - 1
result = result + ((-x) ^ i) / (i + 1)
Next
cal = result
End Function
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim a As Long, s As Long, D As Double, e As Double
D = 0: a = 1: s = 1: e = 1
Do Until Abs(e - D) < 0.0001
D = e
s = s * a
e = e + 1 / s
a = a + 1
Debug.Print e
DoEvents
Loop
Print e
End Sub
Dim a As Long, s As Long, D As Double, e As Double
D = 0: a = 1: s = 1: e = 1
Do Until Abs(e - D) < 0.0001
D = e
s = s * a
e = e + 1 / s
a = a + 1
Debug.Print e
DoEvents
Loop
Print e
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询