杨辉三角 等腰三角形 vb
输出杨辉三角,要三角形的。我做了一下,怎么也弄不出来什么三角形,请高手看一下,最好有解释为什么那样做就可以输出一个三角形的杨辉三角了……感激不尽!!!PrivateSub...
输出杨辉三角,要三角形的。我做了一下,怎么也弄不出来什么三角形,请高手看一下,最好有解释为什么那样做就可以输出一个三角形的杨辉三角了……感激不尽!!!
Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim a() As Integer, i%, j%
If KeyAscii = 13 Then
Picture1.Cls
n = Val(Text2.Text)
Text2.Text = ""
ReDim a(n, n)
For i = 1 To n
For j = 1 To i
If i = j Then
a(i, j) = 1
Else
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
End If
Picture1.Print Tab(25 - 2 * i); a(i, j)
Next j
Next i
End If
End Sub
就在这纠结了:Picture1.Print Tab(25 - 2 * i); a(i, j) 展开
Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim a() As Integer, i%, j%
If KeyAscii = 13 Then
Picture1.Cls
n = Val(Text2.Text)
Text2.Text = ""
ReDim a(n, n)
For i = 1 To n
For j = 1 To i
If i = j Then
a(i, j) = 1
Else
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
End If
Picture1.Print Tab(25 - 2 * i); a(i, j)
Next j
Next i
End If
End Sub
就在这纠结了:Picture1.Print Tab(25 - 2 * i); a(i, j) 展开
3个回答
展开全部
Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim a() As Integer, i%, j%
If KeyAscii = 13 Then
Picture1.Cls
n = Val(Text2.Text)
Text2.Text = ""
ReDim a(n, n)
For i = 1 To n
Picture1.Print Tab(25 - 2 * i);
For j = 1 To i
If i = j Then
a(i, j) = 1
Else
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
End If
Picture1.Print a(i, j);
Next j
Next i
End If
End Sub
'************************************
把Picture1.Print Tab(25 - 2 * i);放到第一个循环For i = 1 To n下面就OK啦!哈哈,给分吧!
Dim a() As Integer, i%, j%
If KeyAscii = 13 Then
Picture1.Cls
n = Val(Text2.Text)
Text2.Text = ""
ReDim a(n, n)
For i = 1 To n
Picture1.Print Tab(25 - 2 * i);
For j = 1 To i
If i = j Then
a(i, j) = 1
Else
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
End If
Picture1.Print a(i, j);
Next j
Next i
End If
End Sub
'************************************
把Picture1.Print Tab(25 - 2 * i);放到第一个循环For i = 1 To n下面就OK啦!哈哈,给分吧!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我的更好看
Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim a() As Integer, i%, j%
Dim n As Integer
Dim sTemp As String
If KeyAscii = 13 Then
Picture1.Cls
n = Val(Text2.Text)
Text2.Text = ""
ReDim a(n + 1, n + 1)
For i = 1 To n
For j = 1 To i
If 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
End If
For i = 1 To n
sTemp = ""
For j = 1 To i
sTemp = sTemp & a(i, j) & " "
Next j
Picture1.Print Tab(25 - 2 * i); sTemp
Next i
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim a() As Integer, i%, j%
Dim n As Integer
Dim sTemp As String
If KeyAscii = 13 Then
Picture1.Cls
n = Val(Text2.Text)
Text2.Text = ""
ReDim a(n + 1, n + 1)
For i = 1 To n
For j = 1 To i
If 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
End If
For i = 1 To n
sTemp = ""
For j = 1 To i
sTemp = sTemp & a(i, j) & " "
Next j
Picture1.Print Tab(25 - 2 * i); sTemp
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Click() Const N = 10
Dim i, j, a(N, N) As Integer For i = 0 To N - 1 a(i, i) = 1 a(i, 0) = 1 Next i
For i = 2 To N - 1
For j = 1 To i - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j) Next j Next i
Print "显示杨辉三角" For i = 0 To N - 1 For j = 0 To i Print a(i, j); Next j Print Next i End Sub
Dim i, j, a(N, N) As Integer For i = 0 To N - 1 a(i, i) = 1 a(i, 0) = 1 Next i
For i = 2 To N - 1
For j = 1 To i - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j) Next j Next i
Print "显示杨辉三角" For i = 0 To N - 1 For j = 0 To i Print a(i, j); Next j Print Next i End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询