等腰的杨辉三角VB代码
PrivateSubForm_Click()DimA()AsLong,NAsInteger,IAsInteger,JAsIntegerN=Val(InputBox("指定...
Private Sub Form_Click()
Dim A() As Long, N As Integer, I As Integer, J As Integer
N = Val(InputBox("指定行数"))
ReDim A(N, N)
For I = 1 To N
For J = 1 To I
If J = 1 Or I = J Then
A(I, J) = 1
Else
A(I, J) = A(I - 1, J - 1) + A(I - 1, J)
End If
Next J
Next I
For I = 1 To N
Print Tab(2 * (N + 2) - 2 * (I + 2) + 3);
For J = 1 To I
Print A(I, J);
Next J
Print
Next I
End Sub
大神帮忙改改 这个打出来的三角形是歪的,在打印的时候判断位数,位数多的就多加空格,这个地方怎么改啊,我总是改成下标越界 展开
Dim A() As Long, N As Integer, I As Integer, J As Integer
N = Val(InputBox("指定行数"))
ReDim A(N, N)
For I = 1 To N
For J = 1 To I
If J = 1 Or I = J Then
A(I, J) = 1
Else
A(I, J) = A(I - 1, J - 1) + A(I - 1, J)
End If
Next J
Next I
For I = 1 To N
Print Tab(2 * (N + 2) - 2 * (I + 2) + 3);
For J = 1 To I
Print A(I, J);
Next J
Next I
End Sub
大神帮忙改改 这个打出来的三角形是歪的,在打印的时候判断位数,位数多的就多加空格,这个地方怎么改啊,我总是改成下标越界 展开
1个回答
展开全部
这样满意不?
Dim A() As Long, N As Integer, I As Integer, J As Integer
N = Val(InputBox("指定行数"))
ReDim A(N, N)
For I = 1 To N
For J = 1 To I
If J = 1 Or I = J Then
A(I, J) = 1
Else
A(I, J) = A(I - 1, J - 1) + A(I - 1, J)
End If
Next J
Next I
For I = 1 To N
Print Tab(2 * (N + 2) - 2 * (I + 2) + 3);
For J = 1 To I
Print Right(" " & CStr(A(I, J)), 2); " ";
Next J
Print
Next I
Dim A() As Long, N As Integer, I As Integer, J As Integer
N = Val(InputBox("指定行数"))
ReDim A(N, N)
For I = 1 To N
For J = 1 To I
If J = 1 Or I = J Then
A(I, J) = 1
Else
A(I, J) = A(I - 1, J - 1) + A(I - 1, J)
End If
Next J
Next I
For I = 1 To N
Print Tab(2 * (N + 2) - 2 * (I + 2) + 3);
For J = 1 To I
Print Right(" " & CStr(A(I, J)), 2); " ";
Next J
Next I
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询