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

沒有留言:

張貼留言

DHT11 (Node-Red) +PostgreSQL 模擬

 DHT11 (Node-Red) +PostgreSQL 模擬 [{"id":"acddd911a6412f0a","type":"inject","z":"08dc4...