【求助】肿么列出杨辉三角????
vb2010吧
全部回复
仅看楼主
level 8
soffio小宇 楼主
@lipeiyi2006
@孙天骁
你俩知道如何列出杨辉三角不???
2012年06月05日 12点06分 1
level 13
不知道
2012年06月05日 13点06分 2
level 13
public sub yanghui(dim value as integer)
if value < 3 then
messagebox.show("请重新输入数组大于3的值!")
else
dim arry as integer[,] = new integer[value,value]
dim s as string,z as string
for i as integer = 0 to value - 1
for j as integer = 0 to i
if i=j also j=0 then
arry(i,y) = 1
else
arry(i,y) = arry(i-1,j-1) + arry(i-1,j)
end if
s &= arry(i,j) & " "
next
z &= s & vbcrlf
next
messagebox.show("数组为:" & vbcrlf & z)
end if
end sub
2012年06月05日 15点06分 3
level 13
有几个地方没注意到。修改:
Public Sub yanghui(ByVal value As Integer)
If value < 3 Then
MessageBox.Show("请重新输入数组大于3的值!")
Else
Dim arry(value, value) As Integer
Dim s As String = "", z As String = ""
For i As Integer = 0 To value - 1
For j As Integer = 0 To i
If i = j AndAlso j = 0 Then
arry(i, j) = 1
Else
arry(i, j) = arry(i - 1, j - 1) + arry(i - 1, j)
End If
s &= arry(i, j) & " "
Next
z &= s & vbCrLf
Next
MessageBox.Show("数组为:" & vbCrLf & z)
End If
End Sub
2012年06月05日 16点06分 4
level 8
soffio小宇 楼主
谢谢~
2012年06月06日 08点06分 5
1