vb程序设计教程答案
输入整数n,显示出具有n行的杨辉三角形。显示n=8的效果。提示1:定义一个二维数组(若用定长数组实现,则数组大一些;若用动态数组,则数组大小用ReDim函数重新定义)。2...
输入整数n,显示出具有n行的杨辉三角形。显示n=8的效果。
提示
1:定义一个二维数组(若用定长数组实现,则数组大一些;若用动 态数组,则数组大小用ReDim函数重新定义)。
2:对下三角个元素进行设置:第一列及对角线上均为1,其余没一个元素正好等于它上面一行的同一列和前一列的两个元素之和。即:a(i,j)=a(i-1,j-1)+a(i-1,j)
3:利用TAB函数确定每列的宽度,使得列对齐。
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1 展开
提示
1:定义一个二维数组(若用定长数组实现,则数组大一些;若用动 态数组,则数组大小用ReDim函数重新定义)。
2:对下三角个元素进行设置:第一列及对角线上均为1,其余没一个元素正好等于它上面一行的同一列和前一列的两个元素之和。即:a(i,j)=a(i-1,j-1)+a(i-1,j)
3:利用TAB函数确定每列的宽度,使得列对齐。
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1 展开
4个回答
展开全部
Option Explicit
Private Sub Command1_Click()
Dim a() As Integer
Dim i, j, n
ReDim a(9, 9)
For i = 1 To 8
Print Tab(25 - i * 2);
For j = 1 To i
a(i, 1) = 1
a(i, i) = 1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1)
Print a(i, j);
Next j
Print
Next i
End Sub
Private Sub Command1_Click()
Dim a() As Integer
Dim i, j, n
ReDim a(9, 9)
For i = 1 To 8
Print Tab(25 - i * 2);
For j = 1 To i
a(i, 1) = 1
a(i, i) = 1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1)
Print a(i, j);
Next j
Next i
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Private Sub Command1_Click()
Dim a() As Integer
Dim i, j, n
ReDim a(9, 9)
For i = 1 To 8
Print Tab(25 - i * 2);
For j = 1 To i
a(i, 1) = 1
a(i, i) = 1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1)
Print a(i, j);
Next j
Print
Next i
End Sub
////////////////////////////////或者这样////////////////////////////
Private Sub Form_click()
Dim a() As Single
n = Val(InputBox("请输入行数", "杨辉三角"))
ReDim a(n + 1, n + 1)
For i = 1 To n
Print Tab(10);
For j = 1 To i
a(i, 1) = 1
a(i, i) = 1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1)
Print a(i, j);
Next j
Print
Next i
End Sub
Private Sub Command1_Click()
Dim a() As Integer
Dim i, j, n
ReDim a(9, 9)
For i = 1 To 8
Print Tab(25 - i * 2);
For j = 1 To i
a(i, 1) = 1
a(i, i) = 1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1)
Print a(i, j);
Next j
Next i
End Sub
////////////////////////////////或者这样////////////////////////////
Private Sub Form_click()
Dim a() As Single
n = Val(InputBox("请输入行数", "杨辉三角"))
ReDim a(n + 1, n + 1)
For i = 1 To n
Print Tab(10);
For j = 1 To i
a(i, 1) = 1
a(i, i) = 1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1)
Print a(i, j);
Next j
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Load()
Me.AutoRedraw = True
Dim N As Integer, I As Integer, J As Integer
N = 8
Dim SS() As Integer
ReDim SS(1 To N, 1 To N)
For I = 1 To N
SS(I, 1) = 1
SS(I, I) = 1
Next
For I = 3 To N
For J = 2 To I - 1
SS(I, J) = SS(I - 1, J - 1) + SS(I - 1, J)
Next
Next
For I = 1 To N
For J = 1 To I
Print SS(I, J) & vbTab;
Next
Print
Next
End Sub
Me.AutoRedraw = True
Dim N As Integer, I As Integer, J As Integer
N = 8
Dim SS() As Integer
ReDim SS(1 To N, 1 To N)
For I = 1 To N
SS(I, 1) = 1
SS(I, I) = 1
Next
For I = 3 To N
For J = 2 To I - 1
SS(I, J) = SS(I - 1, J - 1) + SS(I - 1, J)
Next
Next
For I = 1 To N
For J = 1 To I
Print SS(I, J) & vbTab;
Next
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim a As Integer
Dim i As Integer = 0
Dim forty As Integer = 0
Dim seventy As Integer = 0
Dim aboveSeventy As Integer = 0
For i = 0 To 99
Randomize()
a = 100 * Rnd()
If (a < 40) Then
forty += 1
ElseIf a >= 40 And a <= 70 Then
seventy += 1
Else
aboveSeventy += 1
End If
Next
MessageBox.Show(forty & " " & seventy & " " & aboveSeventy)
Dim i As Integer = 0
Dim forty As Integer = 0
Dim seventy As Integer = 0
Dim aboveSeventy As Integer = 0
For i = 0 To 99
Randomize()
a = 100 * Rnd()
If (a < 40) Then
forty += 1
ElseIf a >= 40 And a <= 70 Then
seventy += 1
Else
aboveSeventy += 1
End If
Next
MessageBox.Show(forty & " " & seventy & " " & aboveSeventy)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询