vb杨辉三角
1121133114641...........................请教这个怎么用vb编程...
1
1 2 1
1 3 3 1
1 4 6 4 1
...........................
请教这个怎么用vb编程 展开
1 2 1
1 3 3 1
1 4 6 4 1
...........................
请教这个怎么用vb编程 展开
展开全部
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 I
End Sub
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
Next I
End Sub
追问
运行后第二行是11 但是题上没有11 怎么弄
追答
如果你的题中没有11,你的题就是错,去看看杨辉三角的样子,去掉那一行并不是什么难事。
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)))
If i 2 Then Print b(i, j); String(k - Len(b(i, j)), " ");
Next j
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询