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

刚学习一星期,莫笑话

我特别喜欢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
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-06-20
两层for就行了呢
sum=0
for i=1 to N
for j=1 to i
sum=sum+j
next j
next i
第2个回答  2009-06-20
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
第3个回答  2009-06-20
先在代码窗口粘贴复制这段代码:
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
End If
End Function
添加一个Commmand控件:
Private Sub Command1_Click()
Dim N As Integer
N = InputBox("输入 N")
For i = 1 To N
Sum = Sum + Factorial(i)
Next
Print Sum
End Sub

VB输入N的值编程计算1!+2!+3!+...+n!
i = InputBox("请输入N的值","提示")result = 0 If IsNumeric(i) Then For m = 1 To n t = 1 For n = 1 To m t = t*n Next n result = result + t Next m MsgBox "结果为: " & result Else MsgBox "N不是数字!", "错误"End If ...

计算1!+2!+3!+...+n!=?用数学方法,C语言编程,vB编程都行.
include<stdio.h> void main() { int n,i,j,sum=0,a=1; printf("键入数n\\n"); if(n==0) {sum=1;} scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { a=a*j; } sum=sum+a; a=1; } printf("\\n%d\\n",sum); } ...

谁知道求1!+2!+...+n!=?的vb程序代码啊!
if n<0 then msgbox"输入错误,请重新输入"end if s=1 for i = 1to n s=s*i t=t+s next i print t end sub 这个的用户界面上有一个label1,一个text1,和一个command1 。text1需要先清空,用户在text1框内随便输入n值。form中就显示结果 。如果用户错误的输入小于零的数,msgbox就...

vb中1!+2!+3!+……n!的代码怎么写
Private Sub Form_Click() n = 10 For a = 1 to n Sum = Sum + f(n) Next For Print SumEnd Sub如果你要一个程序,单击窗体时跳出对话框,输入n并执行运算输出,可以将第二部分代码如下修改:Private Sub Form_Click() n = Inputbox("请输入n") For a = 1 to n Sum = Sum...

VB编程求解:1!+2!+...+n!>10000时n的最小值。单击窗体,在窗体上输出...
While s <= 10000 i = i + 1 t = t * i s = s + t Wend Print "1!+2!+3!+...+"; Trim(Str(i)); "!="; s End Sub 非要用二重循环的话:Private Sub Command1_Click()s = 0 i = 0 While s <= 10000 t = 1 i = i + 1 For j = 1 To i t = t * j ...

vb里面运用计数循环结构计算出1+2+3+...+N 求过程
Dim num, sum As Integer num = a1.Text For i As Integer = 1 To num sum += i Next response.write("1+...+" & num &"=" &sum)a1和a2是页面中的文本框 根据文本框输入的值,计算和,再显示在页面上

怎么在VB中求和
1.用VB求出阶乘数相加的值,分为两个步骤来求,一个是计算阶乘数,然后相加阶乘数。1!+2!+3!+……+n!举个例子。2、首先要理解阶乘知识,4!它是数字1到4的乘法;N!它是1到n的乘积;等等。如下图所示。3.现在我们来编写代码。第一步是定义变量,如下图所示。4、这是一个累加器,所以会...

急求“1!+2!+ ...+n!” 的c语言写法
mian(){int i,j,s;j=1;s=0;for(i=1;i<=20;i++){j=j*i;s=s+j;} printf("1!+2!+……+20!= %d",s);} VB程序 在form1的click事件中写如下代码:j=1 s=0 for i=1 to 20 j=j*i s=s+j next i print "1!+2!+……20!=";s ...

VB 用自定义函数(function),求1!+2!+3!+…+10!并用print显示结果?
Private Sub Command1_click()dim i as integer dim sum as long for i=1 to 10 sum=sum+fact(i)next debug.print sum End Sub function fact(x as integer) as long if x=1 then fact=1 else fact=x*fact(x-1)end if end function -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-...

求vb题代码:求任意个数的阶乘累计和。s=1!+2!+3!+...+n!,n由用户...
If n < 1 Then '判断是否小于1 ,如果小于1就调用已经定义好的过程弹出对话框 Call msg Exit Sub End If For n = 1 To n '求1!到n!阶乘循环n次 sum = sum + func(n) '调用求第n数的的阶乘的函数,计算前1!+n!的和 Next n MsgBox "1!+2!+3!+...+n!为" & sum, ...

相似回答