关于VB如何实现杨辉三角
Option ExplicitFunction Fc(n As Long) Dim arr() As Long, i As Integer, j As Integer, s As String Cls ReDim arr(1 To n, 1 To n) '重定义数组 For i = 1 To n For j = 1 To i If j = 1 Then arr(i, j) = 1 Else arr(i, j) = arr(i - 1, j - 1) ...全部
Option ExplicitFunction Fc(n As Long) Dim arr() As Long, i As Integer, j As Integer, s As String Cls ReDim arr(1 To n, 1 To n) '重定义数组 For i = 1 To n For j = 1 To i If j = 1 Then arr(i, j) = 1 Else arr(i, j) = arr(i - 1, j - 1) arr(i - 1, j) End If Next Next For i = 1 To Val(Text1) For j = 1 To i s = s & arr(i, j) & Space(6 - Len(CStr(arr(i, j)))) Next s = IIf(i Mod 2 = 1, Space(6 * Int((Val(Text1) - i 1) / 2)) & s, Space(6 * Int((Val(Text1) - i) / 2) 3) & s) Print s s = "" NextEnd FunctionPrivate Sub Form_Activate() Text1 = 20End SubPrivate Sub Text1_Change() Cls If IsNumeric(Text1) And Val(Text1) > 0 And Val(Text1) Fc Val(Text1) Else Text1 = "" End IfEnd Sub。
收起