VB编程 制作倒三角形. 急!
当我的输入显示3行的时候,正三角形显示出*********那么如何用VB的FOR命令编写出,当我输入显示3行的时候显示出*********呢?而且当我输入多少的显示行数,...
当我的输入显示3行的时候,正三角形显示出
*
***
*****
那么如何用VB的FOR命令编写出,当我输入显示3行的时候显示出
*****
***
*
呢?
而且当我输入多少的显示行数,它都会形成相反的两个图形呢?
谢谢
那么如果我是按这个方式打的应该做怎么样的修改呢??谢谢
Dim i j As Integer Dim s, s1 As String
s = "★★★★★★★★★★★★★★★★★★★"
lblDisplayTextUp.Text = ""
lblDisplayTextDown.Text = ""
For i = 1 To Convert.ToInt16(Me.txtInputText.Text)
s1 = Mid(s, 1, 2 * i - 1)
Me.lblDisplayTextUp.Text &= Space(20 - 2 * i) & s1 & vbCrLf
For j = 1 To Convert.ToInt16(Me.txtInputText.Text) step -1
s1 = Mid(s, ?, ?)
Me.lblDisplayTextDown.Text &= Space(?) & s1 & vbCrLf
Next
Next
End Sub
End If 展开
*
***
*****
那么如何用VB的FOR命令编写出,当我输入显示3行的时候显示出
*****
***
*
呢?
而且当我输入多少的显示行数,它都会形成相反的两个图形呢?
谢谢
那么如果我是按这个方式打的应该做怎么样的修改呢??谢谢
Dim i j As Integer Dim s, s1 As String
s = "★★★★★★★★★★★★★★★★★★★"
lblDisplayTextUp.Text = ""
lblDisplayTextDown.Text = ""
For i = 1 To Convert.ToInt16(Me.txtInputText.Text)
s1 = Mid(s, 1, 2 * i - 1)
Me.lblDisplayTextUp.Text &= Space(20 - 2 * i) & s1 & vbCrLf
For j = 1 To Convert.ToInt16(Me.txtInputText.Text) step -1
s1 = Mid(s, ?, ?)
Me.lblDisplayTextDown.Text &= Space(?) & s1 & vbCrLf
Next
Next
End Sub
End If 展开
2个回答
展开全部
程序运行的时候单击窗体,要求输入行数。输出相应的对应图形。把代码复制到窗体即可。
代码如下:
Private Sub Form_Click()
Form1.Cls
Dim a, i, j, k As Integer
a = Val(InputBox("请输入行数!"))
For i = 1 To a
For k = 1 To a - i
Print " ";
Next k
For j = 1 To 2 * i - 1
Print "*";
Next j
Print
Next i
For i = a To 1 Step -1
For k = a - i To 1 Step -1
Print " ";
Next k
For j = 1 To 2 * i - 1
Print "*";
Next j
Print
Next i
End Sub
代码如下:
Private Sub Form_Click()
Form1.Cls
Dim a, i, j, k As Integer
a = Val(InputBox("请输入行数!"))
For i = 1 To a
For k = 1 To a - i
Print " ";
Next k
For j = 1 To 2 * i - 1
Print "*";
Next j
Next i
For i = a To 1 Step -1
For k = a - i To 1 Step -1
Print " ";
Next k
For j = 1 To 2 * i - 1
Print "*";
Next j
Next i
End Sub
展开全部
Private Sub Command1_Click()
Dim n%, i%, tmp$()
n = Val(InputBox("请输入显示行数!!"))
ReDim tmp(1 To n * 2)
For i = 1 To n
tmp(i) = Space(n + 1 - i) & String(i * 2 - 1, "*")
tmp(n * 2 + 1 - i) = tmp(i)
Next
Print Join(tmp, vbCrLf)
End Sub
Dim n%, i%, tmp$()
n = Val(InputBox("请输入显示行数!!"))
ReDim tmp(1 To n * 2)
For i = 1 To n
tmp(i) = Space(n + 1 - i) & String(i * 2 - 1, "*")
tmp(n * 2 + 1 - i) = tmp(i)
Next
Print Join(tmp, vbCrLf)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询