3个回答
展开全部
在标准模块些下面函数
Public Function zuhe(ByVal u As Long, ByVal d As Long) As Long
Dim i, a, b As Long
a = 1
b = 1
dd = d - u + 1
For i = d To dd Step -1
a = a * i
Next
For i = u To 1 Step -1
b = b * i
Next
zuhe = a / b
End Function
在对象代码中响应某个按钮的事件,将在窗体上显示杨辉三角,若把i循环中的10改为其他数,可显示不同的级数
Private Sub Command1_Click()
Dim s As String
Dim i, j As Long
For i = 1 To 10
For j = 0 To i
s = s + Str(zuhe(j, i))
Next
Print s
s = ""
Next
End Sub
高中数学讲过二项式定理,应用排列组合的知识就可以解决。函数zuhe()用来算d个中取u个的组合数,不明白借本高二的书看看。
Public Function zuhe(ByVal u As Long, ByVal d As Long) As Long
Dim i, a, b As Long
a = 1
b = 1
dd = d - u + 1
For i = d To dd Step -1
a = a * i
Next
For i = u To 1 Step -1
b = b * i
Next
zuhe = a / b
End Function
在对象代码中响应某个按钮的事件,将在窗体上显示杨辉三角,若把i循环中的10改为其他数,可显示不同的级数
Private Sub Command1_Click()
Dim s As String
Dim i, j As Long
For i = 1 To 10
For j = 0 To i
s = s + Str(zuhe(j, i))
Next
Print s
s = ""
Next
End Sub
高中数学讲过二项式定理,应用排列组合的知识就可以解决。函数zuhe()用来算d个中取u个的组合数,不明白借本高二的书看看。
展开全部
Option Explicit
Private Sub Form_Click()
Dim A() As Long, N As Integer, I As Integer, J As Integer, X As Integer
N = Val(InputBox("请输入打印行数<=16", "输入正整数", 16))
If N > 16 Or N <= 0 Then
MsgBox "数值错误,重新输入行数"
N = 0
End If
ReDim A(N, N)
Frm10.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
Print Spc(75 - 3 * I);
For J = 1 To I
Print A(I, J);
X = Len(CStr(A(I, J)))
If X = 1 Then Print Spc(3);
If X = 2 Then Print Spc(2);
If X = 3 Then Print Spc(1);
Next J
Print
Print
Next I
End Sub
Private Sub Form_Click()
Dim A() As Long, N As Integer, I As Integer, J As Integer, X As Integer
N = Val(InputBox("请输入打印行数<=16", "输入正整数", 16))
If N > 16 Or N <= 0 Then
MsgBox "数值错误,重新输入行数"
N = 0
End If
ReDim A(N, N)
Frm10.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
Print Spc(75 - 3 * I);
For J = 1 To I
Print A(I, J);
X = Len(CStr(A(I, J)))
If X = 1 Then Print Spc(3);
If X = 2 Then Print Spc(2);
If X = 3 Then Print Spc(1);
Next J
Next I
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Load()
Dim i As Long, j As Long
Dim ctArr(10, 10) As Long
For i = 1 To 10
For j = 1 To i
ctArr(1, 1) = 1
ctArr(i, j) = ctArr(i - 1, j - 1) + ctArr(i - 1, j)
ctArr(1, 1) = 1
Debug.Print ctArr(i, j);
Next j
Debug.Print
Next i
End Sub
输出的部分(debug.print)方式自己看着办
Dim i As Long, j As Long
Dim ctArr(10, 10) As Long
For i = 1 To 10
For j = 1 To i
ctArr(1, 1) = 1
ctArr(i, j) = ctArr(i - 1, j - 1) + ctArr(i - 1, j)
ctArr(1, 1) = 1
Debug.Print ctArr(i, j);
Next j
Debug.Print
Next i
End Sub
输出的部分(debug.print)方式自己看着办
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询