VB语言题目:计算y=2/3!+5/6!+8/9!

来源:学生作业学帮网 编辑:学帮网 时间:2024/06/28 23:51:52

VB语言题目:计算y=2/3!+5/6!+8/9!

Private Sub Command1_Click()
  Dim I As Integer, N As Double
  N = 0
  For I = 2 To 8 Step 3
    N = N + I / (Factorial(I + 1))
  Next
  Print N
End Sub
Function Factorial(X As Double) As Double
  If X = 1 Then
    Factorial = 1
  Else
    Factorial = X * Factorial(X - 1)
  End If
End Function