2017年12月13日 星期三

[ VB2010 ] -用遞迴 求算1*2+2*3+3*4+…+(n-1)*n之和.

[ VB2010 ] -用遞迴 求算1*2+2*3+3*4+…+(n-1)*n之和.




Public Class Form1


    Private Function sum(ByVal n As Integer) '/*遞迴程式部分*/
        If (n = 1) Then
            Return 0
        Else
            Return sum(n - 1) + n * (n - 1)
        End If


    End Function

    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 = sum(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

沒有留言:

張貼留言

2025_2 WOKWI & Node-red 4LED Control SQLite

 2025_2 WOKWI &  Node-red  4LED Control SQLite Wokwi程式 #include < WiFi.h > #include < PubSubClient.h > //Relays for switch...