如图 1
22
333
4444
55555
666666
7777777
88888888
999999999
0000000000
【提示】使用Tab函数定打印位置,可使用的函数还有:String, Right,Str
(1)循环体内显示用String函数来实现,找出循环控制变量与Sting函数内个数的关系,即String(j,Trim(str(i)))。
(2)Trim()去空格函数是去掉字符串两边的空格。因为将数值I转换成字符串的时候,系统会自动在数字前面加符号位,正数为空格,负数为“-”;而String函数只取字符串中的首字符,这里是空格,因此要利用Trim函数先去掉空格。
(3)为了使最后一行的0显示,若按照上面的通式,则最后一行显示的是1,则要对公式进行修改,即String(j,Right(str(i)))。
图为等腰三角形
用VB编程如何打印数字金字塔
For i = 1 To 9 For j = 1 To 9 - i Print " "; Next j For j = 1 To i Print j; Next j For j = i - 1 To 1 Step -1 Print j; Next j Print Next i
VB中用循环语句 for 。。next 怎么实现数字金字塔》?
'前面加空格,改成这样:Private Sub Command1_Click()Dim I As Long, nStr As String, S As Long S = 4 '显示的最大数字,可修改 Me.Cls: Me.AutoRedraw = True For I = 1 To S nStr = String(S - I, " ") & String((I - 1) * 2 + 1, I & "")Me.Print nStr Nex...
vb问题 打印数字金字塔的一段代码,请哪位给我解释一下,要详细一点。
Private Sub Form_DblClick() ‘窗体双击事件 For i = 1 To 9 ’外层循环,用于控制打印行数 For T = 1 To i ‘内层循环,用于控制每行的打印列数 Print Tab(10 - i); ’定位首个打印字符的位置。这里可以使用spc(10-i),可以获得相同的效果 Next For j = 1 To i ‘打印字符 Print...
VB中如何计算税后金额并输出数字金字塔??
Private Sub Command1_Click()aaa = Val(InputBox("税前金额", "输入"))If aaa > 2000 Then bbb = (aaa - 2000) * 0.05 If aaa > 10000 Then tax = 8000 * 0.05 bbb = (aaa - 10000) * 0.12 End If If aaa > 50000 Then tax = tax + 40000 * 0.12 bbb = (aaa - 5...
用vb编写打印倒立的数字金字塔,急求。
Private Sub Form_Click()Dim i As Integer, s As String For i = 9 To 0 Step -1 s = String(i * 2 + 1, CStr(i))Print Spc((18 - i * 2) \/ 2);s Next End Sub
vb数字金字塔1 121 12321一直到9
自己看图,是不是这样,我发了两个小时才调好的,我也才学,希望对你有帮助,代码如下:Private Sub Form_Click()Dim a(1 To 5) As Integer For j = 1 To 5 a(j) = j Next j For i = 1 To 5 Print Tab(30 - i * 3);For j = 1 To 2 * i - 1 If j > i Then Print...
用VB的循环结构编写数字金字塔
Private Sub Command1_Click()For i = 1 To 9 Print Spc(9 - i);For j = 1 To i Print Chr(48 + j);Next j For j = i - 1 To 1 Step -1 Print Chr(48 + j);Next j Print Next i End Sub
关于VB数字金字塔
Private Sub Command1_Click()For i = 1 To 9 Print Space(i - 1); For j = 1 To 10 - i Print Trim(j); Next For j = 9 - i To 1 Step -1 Print Trim(j); Next PrintNextFor i = 8 To 1 Step -1 Print Space(i - 1); For j = 1...
如何用VB实现数字金字塔式的图形输出 就像这样 1
Private Sub Command1_Click() For i = 1 To 5 Print Space(6 - i) & Cstr(2 * i - 1); For j = 2 To 2 * i - 1 Print CStr(2 * i - 1); Next j Print Next iEnd Sub
vb程序设计打印数字金字塔
Private Sub Form_Load()Me.AutoRedraw = True For i = -4 To 4 Print Tab(3 + Abs(i)); String(9 - 2 * Abs(i), Trim(Str(i + 5)))Next i End Sub