●用Do ... Loop區塊列出1元,5元,10元,50元硬幣加起來等於100元的排列組合:
●使用While ... End While區塊列出九九乘法表
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim T1, T5, T10, T50, I As Integer
TextBox1.Text = ""
I = 0
Do Until T1 > 100
T5 = 0
Do Until T5 > 20
T10 = 0
Do Until T10 > 10
T50 = 0
Do Until T50 > 2
If (T1 + T5 * 5 + T10 * 10 + T50 * 50) = 100 Then
I = I + 1
TextBox1.Text = TextBox1.Text & Chr(13) + Chr(10) & "第" & I & "排列組合:"
TextBox1.Text = TextBox1.Text & "1元" & T1 & "枚,5元" & T5 &
"枚,10元" & T10 & "枚,50元" & T50 & "枚"
End If
T50 = T50 + 1
Loop
T10 = T10 + 1
Loop
T5 = T5 + 1
Loop
T1 = T1 + 1
Loop
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim I, J As Integer
I = 2
While I <= 9
J = 1
While J <= 9
TextBox1.Text = TextBox1.Text & I & "*" & J & "=" & I * J & "," & Chr(9)
J = J + 1
End While
TextBox1.Text = TextBox1.Text & Chr(13) + Chr(10)
I = I + 1
End While
End Sub
End Class
沒有留言:
張貼留言