关于VB如何实现杨辉三角
要求使用循环语句实现在窗体上显示一个杨辉三角,显示的杨辉三角行数,由用户输入设定。
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。
答:1.正确选定循环变量的初值。比如,对累加问题和连乘问题,变量初值不正确,便影响最终结果。例如计算m=1!+2!+…+10! m=0 n=1 DO20I=1,10...详情>>
答:Adodc1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data S...详情>>
答:If Len(Inet1.OpenURL(" ")) <> 0 Or_ Len(Inet1.OpenURL(" ")) <> 0 Then MsgBox "成功...详情>>