1、具體實現星號三角形的程式碼如下:
Public Function sanjiaoxing(ByVal num As Integer) As String
Dim i, j As Integer
Dim st As String
st = ""
Dim m As Integer
If (num Mod 2 = 0) Then
sanjiaoxing = ""
End If
'輸出上三角形
For i = 1 To (num + 1) \ 2
For j = 1 To (num + 1) / 2 - i
st = st & " "
Next
For j = 1 To 2 * i - 1
st = st & "*"
st = st & vbCrLf
sanjiaoxing = st
End Function
Private Sub Form_Click()
Print sanjiaoxing(11)
End Sub
1、具體實現星號三角形的程式碼如下:
Public Function sanjiaoxing(ByVal num As Integer) As String
Dim i, j As Integer
Dim st As String
st = ""
Dim m As Integer
If (num Mod 2 = 0) Then
sanjiaoxing = ""
End If
'輸出上三角形
For i = 1 To (num + 1) \ 2
For j = 1 To (num + 1) / 2 - i
st = st & " "
Next
For j = 1 To 2 * i - 1
st = st & "*"
Next
st = st & vbCrLf
Next
sanjiaoxing = st
End Function
Private Sub Form_Click()
Print sanjiaoxing(11)
End Sub