visual basic 程序设计的问题
答案:3 悬赏:80 手机版
解决时间 2021-07-25 12:00
- 提问者网友:疯孩纸
- 2021-07-25 01:53
怎样输出一个杨辉三角形
最佳答案
- 五星知识达人网友:空山清雨
- 2021-07-25 02:58
Private Sub Form_Activate()
Dim a() As Single
n = Val(InputBox("请输入行数", "杨辉三角"))
ReDim a(n + 1, n + 1)
For i = 1 To n
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
Dim a() As Single
n = Val(InputBox("请输入行数", "杨辉三角"))
ReDim a(n + 1, n + 1)
For i = 1 To n
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
全部回答
- 1楼网友:醉吻情书
- 2021-07-25 04:09
什么是杨辉三角形 ?告诉我我就会了
- 2楼网友:渊鱼
- 2021-07-25 03:56
Private Sub Command1_Click() Const n = 5 '想出几行,就改这个数 Dim a(n + 1) As Byte, i As Integer, j As Integer Dim s As String '给数组a赋初值 For i = 1 To n + 1 a(i) = 0 Next i '计算并打印第一个数 a(1) = 1 Print Space(2 * n + 2); '计算数字前的空格数 Print a(1) '计算其余行的数并打印 For i = 2 To n + 1 a(i) = a(i - 1) For j = i - 1 To 2 Step -1 a(j) = a(j - 1) + a(j) Next j Print Space((n - i + 1) * 2); For j = 1 To i s = Trim(Str(a(j))) Print Space(Int((4 - Len(s)) / 2 + 0.5)) + s + Space(Int((4 - Len(s)) / 2 + 0.5)); Next j Print Next i
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯