2个回答
2013-07-30
展开全部
Option Explicit
Function 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 = ""
Next
End FunctionPrivate Sub Form_Activate()
Text1 = 20
End SubPrivate Sub Text1_Change()
Cls
If IsNumeric(Text1) And Val(Text1) > 0 And Val(Text1) <= 20 Then '最大20
Fc Val(Text1)
Else
Text1 = ""
End If
End Sub
Function 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 = ""
Next
End FunctionPrivate Sub Form_Activate()
Text1 = 20
End SubPrivate Sub Text1_Change()
Cls
If IsNumeric(Text1) And Val(Text1) > 0 And Val(Text1) <= 20 Then '最大20
Fc Val(Text1)
Else
Text1 = ""
End If
End Sub
推荐于2017-05-24
展开全部
Private Sub Form_click()
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询