求VB大佬看看这哥问题如何解决 谢谢!!
计算公式为:Cmn=m!/(n!*(m-n)!) 展开
Dim jc As Integer = 1
For i = 1 To n
jc = jc * i
Next
Return jc
End Function
Public Function jiecheng(ByVal n As Integer) As Double
Dim jc As Double
jc = 1
For i = 1 To n
jc = jc * i
Next
jiecheng = jc
End Function
Private Function Factorial1(intN As Integer) As Integer
'采用递归计算阶乘
If intN = 0 Then
Factorial1 = 1
Else
Factorial1 = Factorial1(intN - 1) * intN
End If
End Function
给你几个阶乘的函数,你可以直接调用阶乘的函数去做哦
Option Explicit
Private Sub Command1_Click()
Dim M As Double, N As Double
InputData M, "M"
InputData N, "N"
If M < N Then
Print "Combination(" & M & "," & N; ")=" & 0
Else
Print "Combination(" & M & "," & N; ")=" & Factorial(M) / (Factorial(N) * Factorial(M - N))
End If
End Sub
Public Sub InputData(ByRef t, ByVal Char As String)
t = InputBox(Char + "=", "输入框", 25)
If Int(Val(t)) <> Val(t) Or Val(t) < 0 Then
MsgBox "数据错误!请重新输入:", 16
InputData t, Char
End If
End Sub
Public Function Factorial(ByVal r)
Dim i As Integer
Factorial = 1
For i = 1 To r
Factorial = Factorial * i
Next i
End Function