1-2/2!+3/3!-4/4!+…(-1)^n+1*n/n!编写vb程序

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 05:40:32
1-2/2!+3/3!-4/4!+…(-1)^n+1*n/n!编写vb程序

1-2/2!+3/3!-4/4!+…(-1)^n+1*n/n!编写vb程序
1-2/2!+3/3!-4/4!+…(-1)^n+1*n/n!编写vb程序

1-2/2!+3/3!-4/4!+…(-1)^n+1*n/n!编写vb程序
Private Sub Command1_Click()
Dim n%,sum!,fact!
sum = 0
n = InputBox("输入n:","提示信息",1)
If n < 0 Then
MsgBox "数据有误!",48,"警告!"
End If
For i = 1 To n
fact = 1
For j = 1 To i
fact = fact * j
Next j
sum = sum + (-1) ^ (i + 1) * i / fact
Next i
Print sum
End Sub