VB编程。输入整数n,计算1!+2!+3!….+n!的值,并在窗体上输出。要求分别用for,while 两种循环实现
1个回答
展开全部
Dim i As Integer, j As Integer
Dim n As Integer, sum As Long, jc As Long
n = InputBox("请输入:") '如果是用文本框text1输入,这里改为 n=val(Text1)
sum = 0
For i = 1 To n
jc = 1
for j=1 to i
jc = jc * j
next j
sum = sum + jc
Next i
Print sum
while:
Dim i As Integer, j As Integer
Dim n As Integer, sum As Long, jc As Long
n = InputBox("请输入:")
sum = 0
i = 1
While i <= n
jc = 1
j = 1
While j <= i
jc = jc * j
j = j + 1
Wend
sum = sum + jc
i = i + 1
Wend
Print sum
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询