VB 编写一求阶乘的子函数,求C=n!/(m!*(n-m)!)值。即主函数调用3次子函数计算C的值并输出。
答案:3 悬赏:60 手机版
解决时间 2021-04-01 01:49
- 提问者网友:無理詩人
- 2021-03-31 04:00
VB 编写一求阶乘的子函数,求C=n!/(m!*(n-m)!)值。即主函数调用3次子函数计算C的值并输出。
最佳答案
- 五星知识达人网友:动情书生
- 2021-03-31 04:25
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
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim a As Integer, b As Integer
a = Val(InputBox("请输入n"))
b = Val(InputBox("请输入m"))
Dim res As Double
res = jiecheng(a) / (jiecheng(b) * jiecheng(a - b))
TextBox6.Text = res.ToString
End Sub
Dim jc As Integer = 1
For i = 1 To n
jc = jc * i
Next
Return jc
End Function
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim a As Integer, b As Integer
a = Val(InputBox("请输入n"))
b = Val(InputBox("请输入m"))
Dim res As Double
res = jiecheng(a) / (jiecheng(b) * jiecheng(a - b))
TextBox6.Text = res.ToString
End Sub
全部回答
- 1楼网友:逐風
- 2021-03-31 06:02
C=factorial(n)/(factorial(m)*factorial(n-m))
Private Function factorial(ByVal N As Long) As Double
Dim i As Long
Dim sum As Double
sum = 1
For i = 1 To N
sum = sum * i
Next
factorial = sum
End Function追问题里说的调用三次子函数是什么追答子函数就factorial,这是个单独求阶乘的子函数,求C可不调用了三次嘛,你也可以再加个函数当主函数
'主函数
Private Function Main(m As Long, n As Long) As Double
Main1 = factorial(n) / (factorial(m) * factorial(n - m))
End Function
'子函数
Private Function factorial(ByVal N As Long) As Double
Dim i As Long
Dim sum As Double
sum = 1
For i = 1 To N
sum = sum * i
Next
factorial = sum
End Function
Private Function factorial(ByVal N As Long) As Double
Dim i As Long
Dim sum As Double
sum = 1
For i = 1 To N
sum = sum * i
Next
factorial = sum
End Function追问题里说的调用三次子函数是什么追答子函数就factorial,这是个单独求阶乘的子函数,求C可不调用了三次嘛,你也可以再加个函数当主函数
'主函数
Private Function Main(m As Long, n As Long) As Double
Main1 = factorial(n) / (factorial(m) * factorial(n - m))
End Function
'子函数
Private Function factorial(ByVal N As Long) As Double
Dim i As Long
Dim sum As Double
sum = 1
For i = 1 To N
sum = sum * i
Next
factorial = sum
End Function
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯