●在主控台應用程式裡印出15~21:
●在主控台應用程式裡列印出99,97~83,81:
●計算1+2+3+...+998+999+1000的總和:
●計算1+4+7+...+94+97+100的總和:
●列出1元,5元,10元,50元硬幣加起來等於100元的排列組合:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim I As Long
For I = 15 To 21
TextBox1.Text = TextBox1.Text & CStr(I) & Chr(13) + Chr(10)
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim I As Long
For I = 99 To 81 Step -2
TextBox1.Text = TextBox1.Text & CStr(I) & Chr(13) + Chr(10)
Next
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim I As Long
Dim Sum As Long
TextBox1.Text = "●計算1+2+3+...+998+999+1000的總和:"
TextBox1.Text = TextBox1.Text & Chr(13) + Chr(10)
Sum = 0
For I = 1 To 1000
Sum = Sum + I
Next
TextBox1.Text = TextBox1.Text & Chr(13) + Chr(10) & "Sum = " & CStr(Sum)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim I As Long
Dim Sum As Long
Sum = 0
TextBox1.Text = "●計算1+4+7+...+94+97+100的總和:"
TextBox1.Text = TextBox1.Text & Chr(13) + Chr(10)
For I = 1 To 100 Step 3
Sum = Sum + I
Next
TextBox1.Text = TextBox1.Text & Chr(13) + Chr(10) & "Sum=" & Sum
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim T1, T5, T10, T50, I As Integer
TextBox1.Text = "●列出1元,5元,10元,50元硬幣加起來等於100元的排列組合:"
TextBox1.Text = TextBox1.Text & Chr(13) + Chr(10)
For T1 = 0 To 100
For T5 = 0 To 20
For T10 = 0 To 10
For T50 = 0 To 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
Next
Next
Next
Next
End Sub
End Class
沒有留言:
張貼留言