用vb打印一个杨辉三角形~
PrivateSubCommand1_Click()Dimm%,i%,j%,t%Dima(10)AsIntegerFori=1To10a(i)=Int(Rnd*100)N...
Private Sub Command1_Click()
Dim m%, i%, j%, t%
Dim a(10) As Integer
For i = 1 To 10
a(i) = Int(Rnd * 100)
Next i
For i = 1 To 10
Print a(i);
Next i
Print
For i = 1 To 9
m = i
For j = i + 1 To 10
If a(j) > a(m) Then
m = j
Next j
t = a(i)
a(i) = a(m)
a(m) = t
Next i
For i = 1 To 10
Print a(i);
Next i
Print
End Sub
但是运行不出来~~~~怎么回事啊~~帮忙看看啊!! 展开
Dim m%, i%, j%, t%
Dim a(10) As Integer
For i = 1 To 10
a(i) = Int(Rnd * 100)
Next i
For i = 1 To 10
Print a(i);
Next i
For i = 1 To 9
m = i
For j = i + 1 To 10
If a(j) > a(m) Then
m = j
Next j
t = a(i)
a(i) = a(m)
a(m) = t
Next i
For i = 1 To 10
Print a(i);
Next i
End Sub
但是运行不出来~~~~怎么回事啊~~帮忙看看啊!! 展开
4个回答
展开全部
==杨辉三角===============================================================
Private Sub Command3_Click()
Dim a() As Single '设数组A,为单精度型
'通过对话框取得行数,放到变量N中
n = Val(InputBox("请输入行数", "杨辉三角"))
'根据N值重定义数组A为2维的N+1的数组
ReDim a(n + 1, n + 1)
For i = 1 To n '第1层FOR,让I从1,FOR 到N,用来打印行数
For j = 1 To i ' 第2层FOR, 让J从1FOR 到I, 可以胡孙想象,每行的数字因为I的累加, 个数也在变化
a(i, 1) = 1 '让每次数组的最左端为1
a(i, i) = 1 '让每次数组的最右端为1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1) '让数组中间模激的元素等于此元素所在序号的步长加1
Print a(i, j); '打印,数组A(I,J),使用;号使每个J循环中的打印不换行
Next j
Print '每个J循环完裤码链成,打印换行
Next i
End Sub
Private Sub Command3_Click()
Dim a() As Single '设数组A,为单精度型
'通过对话框取得行数,放到变量N中
n = Val(InputBox("请输入行数", "杨辉三角"))
'根据N值重定义数组A为2维的N+1的数组
ReDim a(n + 1, n + 1)
For i = 1 To n '第1层FOR,让I从1,FOR 到N,用来打印行数
For j = 1 To i ' 第2层FOR, 让J从1FOR 到I, 可以胡孙想象,每行的数字因为I的累加, 个数也在变化
a(i, 1) = 1 '让每次数组的最左端为1
a(i, i) = 1 '让每次数组的最右端为1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1) '让数组中间模激的元素等于此元素所在序号的步长加1
Print a(i, j); '打印,数组A(I,J),使用;号使每个J循环中的打印不换行
Next j
Print '每个J循环完裤码链成,打印换行
Next i
End Sub
参考资料: http://hi.baidu.com/%C4%DD%BF%C9%B1%A6%B1%B4/blog/item/324fadf54823eb26bd310923.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'这样就可以了,
Private Sub Command1_Click()
Dim m%, i%, j%, t%
Dim a(10) As Integer
For i = 1 To 10
a(i) = Int(Rnd * 100)
Next i
For i = 1 To 10
Print a(i);
Next i
Print
For i = 1 To 9
m = i
For j = i + 1 To 10
If a(j) > a(m) Then m = j
Next j
t = a(i)
a(i) = a(m)
a(m) = t
Next i
For i = 1 To 10
Print a(i);
Next i
Print
End Sub
Private Sub Command1_Click()
Dim m%, i%, j%, t%
Dim a(10) As Integer
For i = 1 To 10
a(i) = Int(Rnd * 100)
Next i
For i = 1 To 10
Print a(i);
Next i
For i = 1 To 9
m = i
For j = i + 1 To 10
If a(j) > a(m) Then m = j
Next j
t = a(i)
a(i) = a(m)
a(m) = t
Next i
For i = 1 To 10
Print a(i);
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
应该吵升是顷答在
m = i
For j = i + 1 To 10
If a(j) > a(m) Then
m = j
%%%
Next j
这里好像少了个END IF
所雀碰慧以报少了个 for,
m = i
For j = i + 1 To 10
If a(j) > a(m) Then
m = j
%%%
Next j
这里好像少了个END IF
所雀碰慧以报少了个 for,
参考资料: http://zhidao.baidu.com/question/7171528.html?fr=qrl3
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
下面裤厅没有杨辉三角20行的代码,你伏漏可修改后用:
Option Explicit
Dim a(21, 21) As Long
Dim b(21) As String
Dim I As Byte
Dim j As Byte
Private Sub Form_Load()
a(0, 0) = 1
For I = 1 To 20
For j = 1 To 20
a(I, j) = a(I - 1, j - 1) + a(I - 1, j)
If a(I, j) <胡纳> 0 Then
b(j) = b(j - 1) & " " & a(I, j)
End If
Next
Print b(I)
Next
End Sub
Option Explicit
Dim a(21, 21) As Long
Dim b(21) As String
Dim I As Byte
Dim j As Byte
Private Sub Form_Load()
a(0, 0) = 1
For I = 1 To 20
For j = 1 To 20
a(I, j) = a(I - 1, j - 1) + a(I - 1, j)
If a(I, j) <胡纳> 0 Then
b(j) = b(j - 1) & " " & a(I, j)
End If
Next
Print b(I)
Next
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询