[ VB2010 ] - 遞迴程式 --輸入兩個數M及N,計算M取N的值
輸入兩個數M及N,計算M取N的值,亦即M!/(N!(M-N)!)
/* 程式功能: 輸入兩個數M及N,計算M取N的值,亦即M!/(N!(M-N)!) */
Public Class Form1
Private Function factorial(ByVal n As Integer) '/*遞迴程式部分*/
If n = 1 Then
Return 1
Else
Return n * factorial(n - 1)
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim m, n As Integer
m = Val(TextBox2.Text)
n = Val(TextBox3.Text)
TextBox4.Text = (factorial(m) / (factorial(n) * factorial(m - n))).ToString
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
End Class
沒有留言:
張貼留言