求助,vb编程题目两题,能回答任何一题我都给分!

2024-11-13 10:08:57
推荐回答(3个)
回答1:

第一题:
计算函数:
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

回答2:

第一题:
运行条件: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

回答3:

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