Function c(ByVal m As Integer) As Long
If m = 0 Then
c = 1 ' Return 1 不是用这个返回, 直接赋值
Else
c = m c(m - 1) 'Return m c(m - 1) '同上
End If
End Function
Private Sub Button1_Click(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Button1Click
Dim N As Integer , M As Integer , a As Integer, b As Integer
Dim x1 as long , x2 as long , x3 as long
N =val (TextBox1Text) 'N = TextBox1Text
M = val(TextBox2Text ) 'M = TextBox2Text
If N > M Then
a = N - M
x1 = c(N)
x2 = c(M)
x3 = c(a)
b = x1 / (x2 x3)
TextBox3Text = b
End If
End Sub
Private Sub Command1_Click()
Dim A, B, C
A = 10
B = 3
C = f(A) / (f(B) f(A - B))
Print C
End Sub
Private Function f(n)
Dim I As Integer
f = 1
For I = 1 To n
f = f I
Next I
End Function
'X的阶乘并求和
Function SumJC(X As Integer) As Double
rst = 0
For I = 1 To X '求和
jc = 1
For j = 1 To I '计算阶乘
jc = jc j
Next
rst = rst + jc
Next
SumJC = rst
End Function
,测试
Sub T()
'X=1!+2!+3!+4!+5!+6!+7!+8!+9!+10!
'4037913
X = SumJC(10)
MsgBox X
End Sub
程序源代码:
/
计算大数的阶乘,算法的主要思想就是将计算结果的每一位用数组的一位来表示:如要计算5!,那么首先将
(1)
a[0]=1,然后a[0]=a[0]2,a[0]=2,
(2)
a[0]=a[0]3,a[0]=6
(3)
a[0]=a[0]4,a[0]=24,此时a[1]=2,a[0]=4
/
public
class
Factorial
{
static
int
a[]
=
new
int
[10000];
static
void
factorial(int
n)
{
for(int
i=2;
i<
alength;
i++)
a[i]
=
0;
//将数组元素初始化
a[0]
=
1;
//用数组的一项存放计算结果的位数
a[1]
=
1;
//将第一项赋值为一
for(int
j=
2;
j
<=
n;
j++)
{
int
i=1;
int
c
=
0;
//c表示向高位的进位
for(;
i
<=
a[0];
i++)
{
a[i]
=
a[i]
j
+
c;//将来自低位的计算结果和本位的结果相加
c
=
a[i]
/
10;
a[i]
=
a[i]
%
10;
}
for(;
c
!=
0;
i++)
{
a[i]
=
c%10;
c
=
c
/
10;
}
a[0]
=
i
-
1;
没有任意数的,EXCEL中到175以后就已经非常大了,溢出错误
你是不是要在ACCESS中做个自定义函数求
Public Function fac(x As Long)
fac = 1
For i = 1 To x
fac = fac i
Next i
End Function
我这里没有帮你加错误判断进去,数值太大就会溢出的
以上就是关于用VB编一求阶乘的函数f(n),主调程序求组合数的程序,分别调用f(n),用来计算组合数的值全部的内容,包括:用VB编一求阶乘的函数f(n),主调程序求组合数的程序,分别调用f(n),用来计算组合数的值、用VB.NET编写一个程序 :编一求阶乘的函数f(n),主调程序求组合数的程序,分别调用f(n),用来计算组合数的值、求各位大神用VBA编写一到十阶乘相加,万分火急,不尽感谢等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)