2017年12月13日 星期三

[ VB2010 ] - 遞迴程式 --計算N!值

[ VB2010 ] - 遞迴程式 --計算N!值


Example1  計算N!值
Example2  計算M取N的值
Example3  計算1-N的和
Example4  計算(N-1)N的值
Example5  求最大公因數
Example6  輸入兩數字A, B,利用遞迴求得A的B次方
Example7  二元搜尋法 (binary search)
Example8  陣列元素總和






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 Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim n As Integer
        n = Val(TextBox2.Text)
        TextBox3.Text = factorial(n).ToString()
    End Sub
End Class

沒有留言:

張貼留言

Node-Red --> MQTT --> Fuxa

Node-Red --> MQTT --> Fuxa      FUXA(一個開源的 Web HMI / SCADA 自動化監控軟體)的專案設定檔 。 這份設定檔完整定義了 HMI 監控畫面的 後端通訊(MQTT 連線、點位標籤) 與 前端網頁圖形介面(SVG 畫布...