用VB.NET编写一个程序 :编一求阶乘的函数f(n),主调程序求组合数的程序,分别调用f(n),用来计算组合数的值
组合数公式n!/m!(n-m)!“!”表示阶乘谢啦我的程序总是提示确保不会除零我郁闷了。。。PublicClassForm1PrivateSubButton1_Click...
组合数公式 n!/m!(n-m)! “!”表示阶乘 谢啦 我的程序总是提示确保不会除零 我郁闷了。。。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a%, b%, r%, t%
a = TextBox1.Text
b = TextBox2.Text
t = a - b
r = c(a) / (c(b) * c(t))
TextBox3.Text = r
End Sub
Function c(ByVal m As Long) As Integer
Dim x As Long
c = 1
For x = 1 To m
c = c * x
Next
End Function 展开
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a%, b%, r%, t%
a = TextBox1.Text
b = TextBox2.Text
t = a - b
r = c(a) / (c(b) * c(t))
TextBox3.Text = r
End Sub
Function c(ByVal m As Long) As Integer
Dim x As Long
c = 1
For x = 1 To m
c = c * x
Next
End Function 展开
3个回答
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建议在取得a、b后,进行数值的合法性检验。显然必须满足:a、b都是自然数,ab>0,a>b。如果a、b的值不合适,中止程序或要求重填TextBox。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
...
dim x1,x2,x3 as integer
x1 = c(a)
x2 = c(b)
x3 = c(t)
r = x1 / (x2 * x3 == 0 ? 1 : x2 * x3)
...
Function c(ByVal m As Long) As Integer
if m == 0 return 1
else return m*c(m-1)
End Function
dim x1,x2,x3 as integer
x1 = c(a)
x2 = c(b)
x3 = c(t)
r = x1 / (x2 * x3 == 0 ? 1 : x2 * x3)
...
Function c(ByVal m As Long) As Integer
if m == 0 return 1
else return m*c(m-1)
End Function
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询