2008年5月16日 星期五

正反三角形


Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j As Integer
Dim output As String = ""
For i = 1 To 9

For j = 1 To i
output = output & i
Next j
output &= vbNewLine
Next i
txtoutput.Text = output
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i, j As Integer
Dim output As String = ""
For i = 9 To 1 Step -1
For j = 1 To i
output = output & i
Next j
output &= vbNewLine
Next i
txtoutput.Text = output
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim i, j, k, star As Integer
Dim output As String = ""
star = 1
For i = 9 To 1 Step -1
For j = 1 To i
output = output & " "
If j = i Then
For k = 1 To star
output = output & "*"
Next k
Else
output = output & " "
End If
Next j
star = star + 2
output &= vbNewLine
Next i
txtoutput.Text = output
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim i, j, k, star As Integer
Dim output As String = ""
star = 17
For i = 1 To 9
For j = 1 To i
output = output & " "
If j = i Then
For k = 1 To star
output = output & "*"
Next k
Else
output = output & " "
End If
Next j
star = star - 2
output &= vbNewLine
Next i
txtoutput.Text = output
End Sub
End Class

沒有留言: