vb中求1到n阶乘的和

如题所述

第1个回答  推荐于2017-12-15
我没有自己写,也是百度搜索的,看下有没有帮助:
在窗体上放一个命令按纽,计算结果将在窗体上输出,代码如下(直接拷贝)
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer
a = 2
b = 4
c = 6
nn a, b, c
End Sub
Sub nn(a As Integer, b As Integer, c As Integer)
Dim i As Integer, j As Integer, k As Integer, s1 As Integer, s2 As Integer, s3 As Integer
s1 = 1
s2 = 1
s3 = 1
For i = 1 To a
s1 = s1 * i
Next i
For j = 1 To b
s2 = s2 * j
Next j
For k = 1 To c
s3 = s3 * k
Next k
Print "2!+4!+6!=" & s1 + s2 + s3
End Sub本回答被网友采纳
第2个回答  推荐于2018-02-06
Private Sub Command1_Click()
n = InputBox("输出最大阶乘数的值")
j = 1
For i = 1 To n
j = j * i '每个数的阶乘值
s = s + j '合
Next i
Print s
End Sub本回答被网友采纳
第3个回答  2011-01-10
Sum = 0
temp = 1
For i = 1 To n
Sum = Sum + temp * i
temp = temp * i
Next本回答被提问者和网友采纳

怎么在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编程输入任意一个正整数N如果N为偶数,求N的阶乘如果N为奇数,求1...
N = Integer.Parse(Console.ReadLine())If N Mod 2 = 0 Then ' 如果 N 是偶数,计算 N 的阶乘 Dim factorial As Long = 1 For i As Integer = 2 To N Step 2 factorial *= i Next Console.WriteLine("N 的阶乘为:" & factorial)Else ' 如果 N 是奇数,计算 1 到 N 的累加和 ...

vb中求1到n阶乘的和
b = 4 c = 6 nn a, b, c End Sub Sub nn(a As Integer, b As Integer, c As Integer)Dim i As Integer, j As Integer, k As Integer, s1 As Integer, s2 As Integer, s3 As Integer s1 = 1 s2 = 1 s3 = 1 For i = 1 To a s1 = s1 * i Next i For j = 1 T...

求vb题代码:求任意个数的阶乘累计和。s=1!+2!+3!+...+n!,n由用户输入...
For n = 1 To n '求1!到n!阶乘循环n次 sum = sum + func(n) '调用求第n数的的阶乘的函数,计算前1!+n!的和 Next n MsgBox "1!+2!+3!+...+n!为" & sum, vbInformation, "结果"End Sub '求第n个数的阶乘函数 Function func(n As Double) As Double Dim i As Doubl...

vb编程计算1到n阶乘的倒数和
Private Function f(ByVal x%)If x = 1 Then f = 1 Else f = x * f(x - 1)End If End Function Private Sub Form_Click()Dim n%, s!n = InputBox("请输入一个正整数n:")For i = 1 To n m = f(i)s = s + 1 \/ m Next Print "n项阶乘倒数的和为:"; s End Sub...

求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 ...

阶乘之和1+2!+3!+...+10! 用vb的function函数实现
Function JieChengSum() As Long Dim Sum As Long Dim i As Long Dim j As Long Sum = 0 j = 1 For i = 1 To 10 j = j * i Sum = Sum + j Next JieChengSum = Sum End Function 下面是函数的调用示例 Private Sub Command1_Click()MsgBox JieChengSum End Sub ...

VB中的求阶乘之和的问题
还有一个求和的 Private Sub Command2_Click()Dim s As Long, k As Integer, a As Integer a = Val(Text1.Text)Print f(a)End Sub Function f(n) As Long s = 1: Sum = 1 For k = 2 To n s = s * k Sum = Sum + s Next f = Sum End Function 这样运行就OK啦 ...

如何vb双循环做阶乘的累积和?
Public Function jiecheng(ByVal n As Integer) As Integer Dim jc As Integer = 1 For i = 1 To n jc = jc * i Next Return jc End Function

相似回答