用VB编程计算:1!+2!+3!+4!+…+n!

2024-11-18 10:54:52
推荐回答(1个)
回答1:

新建一个工程,添加个命令按钮和一个文本框
代码如下:
Private Sub Command1_Click()

n = Val(Text1.Text)

s = 0 '存结果
For i = 1 To n
t = 1 '临时存积的变量
For j = 1 To i '计算阶乘
t = t * j
Next j
s = s + t
Next i
Print "结果为:" & s

End Sub