VB编程,如何下面程序的杨辉三角成等腰三角形
Dim i As Integer, j As Integer
Dim n As Integer
Dim a() As Integer
n = Val(Text1.Text)
ReDim a(1 To n, 0 To n)
a(1, 1) = 1
For i = 2 To n
For j = 1 To n
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next
Next
For i = 1 To n
For j = 1 To n - i
Print " ";
Next
For j = 1 To i
Print a(i, j) & " ";
Next
Next 展开
输入如下函数即可:
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim n As Integer
Dim a() As Integer
n = Val(Text1.Text)
ReDim a(1 To n, 0 To n)
a(1, 1) = 1
For i = 2 To n
For j = 1 To n
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next
Next
For i = 1 To n
Print Spc(2 * (n - i));
For j = 1 To i
Print Format(a(i, j), "@@@@");
Next
Next
End Sub
扩展资料:
VB数学函数
1、Abs 函数
返回数字的绝对值。
Abs(number) number 参数可以是任意有效的数值表达式。
如果number包含Null,则返回Null如果是未初始化变量,则返回 0。
数字的绝对值是其无符号的数值大小。例如,Abs(-1)和Abs(1) 都返回1。
2、Atn函数返回数值的反正切值。
Atn(number) number 参数可以是任意有效的数值表达式。
说明 Atn 函数计算直角三角形两个边的比值 (number) 并返回对应角的弧度值。此比值是该角对边的长度与邻边长度之比。结果的范围是从 -pi/2 到 pi/2 弧度。
弧度变换为角度的方法是将弧度乘以 pi/180。
3、Cos 函数 返回某个角的余弦值。Cos(number) number 参数可以是任何将某个角表示为弧度的有效数值表达式。
参考资料来源:百度百科-Visual Basic
已经修改完成:
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim n As Integer
Dim a() As Integer
n = Val(Text1.Text)
ReDim a(1 To n, 0 To n)
a(1, 1) = 1
For i = 2 To n
For j = 1 To n
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next
Next
For i = 1 To n
Print Spc(2 * (n - i));
For j = 1 To i
Print Format(a(i, j), "@@@@");
Next
Next
End Sub