VB编程,输入整数N,计算1!+2!+.....+N!=

来源:百度知道 编辑:UC知道 时间:2024/06/15 05:24:51
刚学习一星期,莫笑话

我特别喜欢VB,以后有什么困难请发邮件给我(156095502@163.com),很乐意为您服务!

Private Sub Command1_Click()
n = InputBox("请输入一个整数:", "提示", "")
ss = 0
For i = 1 To n
si = 1
For j = 1 To i
si = si * j
Next j
ss = ss + si
Next i
MsgBox "1!+2!+...+n!=" & Trim(Str(ss))
End Sub

public function f(x as integer)
f=1
for a=1 to x
f=f*a
next a
end function

private sub form_load()
t=0
for a=1 to inputbox("输入N")
t=t+f(a)
next a
print t
end sub

两层for就行了呢
sum=0
for i=1 to N
for j=1 to i
sum=sum+j
next j
next i

先在代码窗口粘贴复制这段代码:
Function Factorial(ByVal n As Integer) As Long'求阶乘函数
If n < 0 Then
Factorial = 0 '小于0则得0
Else
Factorial = 1
For i = 1 To n
Factorial = Factorial * i
Next