2017年12月13日 星期三

[ VB2010 ] -用遞迴方法 求輸入兩數字A, B,利用遞迴求得A的B次方

[ VB2010 ] -用遞迴方法  求輸入兩數字A, B,利用遞迴求得A的B次方




Public Class Form1


    Private Function power(ByVal a As Integer, ByVal b As Integer) '/*遞迴程式部分*/

        If (b = 0) Then
            Return 1
        ElseIf (b = 1) Then
            Return a
        Else
            Return (a * power(a, b - 1))
        End If

    End Function


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a, b As Integer

        a = Val(TextBox2.Text)
        b = Val(TextBox3.Text)

        TextBox4.Text = power(a, b).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


沒有留言:

張貼留言

Exploring Node-Red, Dashboard 2.0, and MQTT

  Exploring Node-Red, Dashboard 2.0, and MQTT 參考來源 https://www.donskytech.com/node-red-dashboard-2-0-mqtt/#google_vignett e #include < A...