输入整数n,显示出具有n行的杨辉三角形。VB编程,跪求。
5个回答
展开全部
源代码如下:
Private Sub Form_Click() N = InputBox("", "", 5) ReDim a(N + 1, N + 1), b(N + 1, N + 1) Cls k = 8 For I = 1 To N Print String((N - I) * k / 2 + 1, " "); 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) b(I, J) = Trim(Str(a(I, J))) Print b(I, J); String(k - Len(b(I, J)), " "); Next J Print Next IEnd Sub运行程序,在文本框输入8,再点窗体,效果图如下:
扩展资料:
杨辉三角在Java中的代码如下:
展开全部
''输出杨辉三角形
Private Sub Command1_Click()
Dim x As String, i As Integer, j As Integer, n As Integer
Dim a() As Integer
n = Val(InputBox("请输入行数:"))
ReDim a(1 To n, 1 To 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
x = ""
For j = 1 To i
x = x & a(i, j) & Space(1)
Next j
Print Space(n - i + 5) & x & Chr(13)
Next i
End Sub
'调试成功
Private Sub Command1_Click()
Dim x As String, i As Integer, j As Integer, n As Integer
Dim a() As Integer
n = Val(InputBox("请输入行数:"))
ReDim a(1 To n, 1 To 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
x = ""
For j = 1 To i
x = x & a(i, j) & Space(1)
Next j
Print Space(n - i + 5) & x & Chr(13)
Next i
End Sub
'调试成功
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Click()
Dim A() As Long, N As Integer, I As Integer, J As Integer
N = Val(InputBox("请输入"))
ReDim A(N, N)
Me.Cls
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
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)
Me.Cls
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
For J = 1 To I
Print A(I, J);
Next J
Next I
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub yh(ByVal n As Integer)
Dim a(n, n) As Integer
For i As Integer = 0 To n
a(i, 0) = 1
Next
For i = 0 To n - 1
For j As Integer = 1 To i
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next
Next
Label1.Text = ""
For i = 0 To n - 1
For j = 0 To i
Label1.Text += a(i, j).ToString() + " "
Next
Label1.Text += vbCrLf
Next
End Sub
Dim a(n, n) As Integer
For i As Integer = 0 To n
a(i, 0) = 1
Next
For i = 0 To n - 1
For j As Integer = 1 To i
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next
Next
Label1.Text = ""
For i = 0 To n - 1
For j = 0 To i
Label1.Text += a(i, j).ToString() + " "
Next
Label1.Text += vbCrLf
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这些都是我做过的考试要求,- - 不过忘记了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询