我的目的是要输出杨辉三角,但我的程序输出的结果却是:
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
我的程序是:
Private Sub Form_Click()
Dim n As Integer, i As Integer, j As Integer
Do
n = InputBox("请输入0<n<10", "n", "6")
Loop While n < 1 Or n > 9
For i = 0 To n
Print Tab(21 - 3 * i)
For j = 0 To i
Print zh(i, j); Spc(5);
Next j
Print
Next i
End Sub
Private Function fact(k As Integer) As Long
Dim i As Integer
fact = 1
For i = 2 To k
fact = fact * i
Next i
End Function
Private Function zh(m As Integer, n As Integer) As Long
zh = fact(m) / fact(n) / fact(m - n)
End Function
真不知道哪里出了问题?希望高手予以指出,谢谢!
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
我的程序是:
Private Sub Form_Click()
Dim n As Integer, i As Integer, j As Integer
Do
n = InputBox("请输入0<n<10", "n", "6")
Loop While n < 1 Or n > 9
For i = 0 To n
Print Tab(21 - 3 * i)
For j = 0 To i
Print zh(i, j); Spc(5);
Next j
Next i
End Sub
Private Function fact(k As Integer) As Long
Dim i As Integer
fact = 1
For i = 2 To k
fact = fact * i
Next i
End Function
Private Function zh(m As Integer, n As Integer) As Long
zh = fact(m) / fact(n) / fact(m - n)
End Function
真不知道哪里出了问题?希望高手予以指出,谢谢!