在命令按钮Command1的单击事件中计算m!/(n!*(m-n)!)的值,并在标签Label4中输出;当输入的m小于n时,直接在标签Label4中输出:"error" (不包括引号)
其中m、n依次分别由文本框Text1和Text2输入。
要求使用函数过程Factorial(n)实现计算n!。
说明:
1)不要更改函数名Factorial
2)函数参数n为整型
【我做的】
Function factorial(n As Integer) As Double
Dim i As Integer, T As Double
T = 1
For i = 1 To n
T = T * i
Next i
factorial = T
End Function
Private Sub Command1_Click()
Dim m As Integer, n As Integer
m = Val(Text1.Text): n = Val(Text2.Text)
If m < n Then
Label4.Caption = "error"
Exit Sub
End If
Label4.Caption = factorial(m) / (factorial(n) * factorial(m - n))
End Sub
慕容708150
小怪兽爱吃肉