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


沒有留言:

張貼留言

Node-Red & ModeBus FC=1

Node-Red & ModeBus FC=1 write address=0..7   8bits read address=16..23 8bits  [{"id":"cf7c1253d4d997dd","type&q...