VB xn函数是什么

来源:百度知道 编辑:UC知道 时间:2024/06/23 06:46:48
用xn函数代替^编以下代码 Z=(x+2)^2+(x+3)^3+(x+4)^4+....+(x+N)^N 本人十分的感谢

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

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