VB xn函数是什么

2024-11-29 23:58:32
推荐回答(2个)
回答1:

Option Explicit
Dim x As Single

Private Sub Command1_Click()
Dim n As Integer, i As Integer, z As Single
Do
n = Val(InputBox("请输入最高指数(>2)"))
Loop Until n > 2
x = Val(InputBox("请输入自变量x"))
z = 0
For i = 2 To n
z = z + xn(i)
Next i
Print z
End Sub

Private Function xn(n As Integer)
Dim x1 As Single, i As Integer
x1 = x + n
xn = 1
For i = 2 To n
xn = xn * x1
Next i
End Function

回答2:

Option Explicit
Dim x As Single
Private Sub Command1_Click()
Dim n As Integer, i As Integer, z As Single
Do
n = Val(InputBox("请输入最高指数(>2)"))
Loop Until n > 2
x = Val(InputBox("请输入自变量x"))
z = 0
For i = 2 To n
z = z + xn(i)
Next i
Print z
End Sub
Private Function xn(n As Integer)
Dim x1 As Single, i As Integer
x1 = x + n
xn = 1
For i = 2 To n
xn = xn * x1
Next i
End Function