用VB求阶乘和

求阶乘和1!+2!+……+10!。要求:
(1) 单击开始按钮后,将结果输出显示在窗体上。
(2) 使用Function过程计算某个数的阶乘。

第1个回答  2011-05-25
Public Function f(m As Integer) As Long
Dim i As Integer, s As Long
s = 1
For i = 1 To m
s = s * i
Next i
f = s
End Function

Private Sub Command1_Click()
Dim i As Integer, s As Long
s = 0
For i = 1 To 10
s = s + f(i)
Next
Print s
End Sub
第2个回答  推荐于2017-09-04
Private Sub Command1_Click()
For i = 1 To 10
Sum = Sum + jiecheng(i)
Next
Print Sum
End Sub

Function jiecheng(num)
jiecheng = 1
For i = 1 To num
jiecheng = jiecheng * i
Next
End Function本回答被提问者采纳
第3个回答  2011-05-25
Private Sub Command1_Click()
For i = 1 To 10
aa = aa + JiCheng(i)
Next
Print aa
End Sub
Private Function JiCheng(ByVal Int_A As Integer) As Long
JiCheng = 1
For i = 1 To Int_A
JiCheng = JiCheng * i
Next i
End Function
第4个回答  2011-05-27
我也不知道追问

hehe....上面三个都可以运行出结果的

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

“求1到10的阶乘之和”用VB怎么编程序
为了编写一个VB程序计算1到10的阶乘之和,首先定义一个函数用于计算阶乘。命名为factorial,并接收一个整数参数n。在函数内部,初始化一个变量l为1,然后使用For循环从1到n,每次将l乘以当前的循环变量i。循环结束后,将l的值作为阶乘返回。接着,在主程序中添加一个按钮控件Command1。定义一个结果变量...

如何用VB语言编程求数学阶乘?
1、首先定义一个函数,这个函数里的内容求n的阶乘,返回值是n的阶乘,如下图所示。2、函数定义完成之后,就要开始写main函数里的内容,还是定义变量。3、变量定义后就要赋值,把sum的值写为0.因为后面的求和就需要sum的初始值为0,如下图所示。4、下一步就是利用for循环了,for循环i初始值位1,结束...

VB编程输入任意一个正整数N如果N为偶数,求N的阶乘如果N为奇数,求1...
Console.WriteLine("N 的阶乘为:" & factorial)Else ' 如果 N 是奇数,计算 1 到 N 的累加和 Dim sum As Long = 0 For i As Integer = 1 To N sum += i Next Console.WriteLine("1 到 N 的累加和为:" & sum)End If Console.ReadLine()End Sub End Module 这段代码首先要求用户...

VB求1-20的阶乘之和
j As Integer Dim sum, t As Double sum = 0 For i = 1 To 20 t = 1 For j = 1 To i t = t * j Next j sum = t + sum Next i MsgBox "1-20的阶乘之和为:" & sum, vbInformation, "确认"你要先建立一个窗体,在窗体上建个按钮,再将上述代码粘贴到按钮的过程内。

编程vb 1到13的阶乘的和
'你可以这样写:private function steptimes(byval times as integer)as long '自定义介乘函数 dim p as long,i as integer p=1 for i=1 to times p=p*i next i steptimes=p end function private sub form_load()msgbox steptimes(13)'调用介乘函数 end sub ...

在VB中求阶乘的代码
在VB中求阶乘的部分代码:Private Function fact(m As Integer) As Long Dim i As Integer fact = 1 For i = 1 To m fact = fact * i Next i End Function Private Sub Command1_Click()Dim n As Integer, sum As Long Dim i As Integer n = Val(Text1.Text)For i = 1 To ...

求1到20的阶乘的累加和的VB代码
'给个参考程序。朋友。private sub form_click()dim n as integer,m as long,sum as long m = 1 sum = 0 n = val(inputbox("输入一个正整数"))for i = 1 to n m = m i sum = sum + m next i print n & "的阶乘和是"& sum end sub ...

vb 求阶乘之和 1!+2!+3!+4!+...+20! 代码是否正确
更正的方法是:把“Item = 1”移到“Do While n <= 20 ”之后。即:Private Sub Form_Click()Dim n#,b b = 0 n = 1 Do While n <= 20 Item = 1 For i = 1 To n Item = Item i Next i b = b + Item n = n + 1 Loop Print "b=";b End Sub ...

求5到15阶乘的和的vb编程
Private Sub Form_Click()Dim i, j As Integer Dim totalnum As Long Dim num As Long num = 1 For i = 5 To 15 For j = i To 2 Step -1 num = num * j Next totalnum = totalnum + num num = 1 Next Print "5!+6!+...+15!=" & totalnum End Sub ...

相似回答