您可能會喜歡......

2018年4月21日 星期六

計算數字為2的?次方或求2的n次方 程式碼

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim n As Integer
        n = TextBox1.Text
        Label1.Text = 2 ^ TextBox1.Text
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim m As Integer
        m = TextBox2.Text
        Dim ans As Integer
        Do Until m = 1
            ans += 1
            m /= 2
        Loop
        Label2.Text = ans
    End Sub
End Class