作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/15 14:17:53
VB语言题目:计算y=2/3!+5/6!+8/9!
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