1、1. Fibonacci 函数。Private Sub Command1_Click()Dim n As Integern = Text1Text2 = fib(n)End SubFunction fib(ByVal x As Integer) As IntegerIf x = 1 Or x = 2 Thenfib = 1Elsefib = fib(x - 2) + fib(x - 1)End IfEnd FunctionPrivate Sub Command2_Click()Text1 = “Text2 = “Text1.SetFocusEnd SubPrivate Sub Command3
2、_Click()EndEnd Sub2. 百元百鸡Private Sub cmdCalc_Click()变量说明Dim x As IntegerDim y As IntegerDim z As Integer穷举法计算For x = 1 To 20For y = 1 To 33z = 100 - x - yIf 5 * x + 3 * y + z / 3 = 100 ThenText1 = Text1 NextPicture1.PrintNextEnd SubPrivate Sub Command2_Click()Text1 = fun1(a)End SubFunction fun1(x()
3、As Integer) As DoubleDim i As Integer, j As Integerfun1 = 0For i = LBound(x, 1) To UBound(x, 1)For j = LBound(x, 2) To UBound(x, 2)If Not (i = LBound(x, 1) Or i = UBound(x, 1) Or j = LBound(x, 2) Or j = UBound(x, 2) Thenfun1 = fun1 + x(i, j)End IfNextNextEnd FunctionPrivate Sub Command3_Click()Text1
4、 = “Picture1.ClsCommand1.SetFocusEnd SubPrivate Sub Command4_Click()EndEnd Sub4. 递归函数Private Sub Command1_Click()List1.ClearDim i As IntegerFor i = 1 To 7List1.AddItem fact(i)Next iEnd SubFunction fact(ByVal n As Double) As DoubleIf n = 1 Thenfact = 1Elsefact = n * fact(n - 1)End IfEnd FunctionPriva
5、te Sub Command2_Click()List1.ClearEnd SubPrivate Sub Command3_Click()EndEnd Sub5. 回文数Private Sub Command1_Click()RandomizeDim i As Integer, x As Integer, min As IntegerFor i = 1 To 500x = Int(Rnd * 9000) + 1000Text1 = Text1 & x & vbCrLfIf HuiWenShu(x) ThenText2 = Text2 & x & vbCrLfIf min = 0 Thenmin
6、 = xElseIf min x Thenmin = xEnd IfEnd IfEnd IfNext iText3 = minEnd SubFunction HuiWenShu(ByVal a As Integer) As BooleanIf StrReverse(a) = a ThenHuiWenShu = TrueElseHuiWenShu = FalseEnd IfEnd FunctionPrivate Sub Command2_Click()Text1 = “Text2 = “Text3 = “End SubPrivate Sub Command3_Click()EndEnd Sub6. 级数求和。Private Sub Command1_Click()Dim s As Double, n As LongDim m As Doubles = 0n = 1Dom = 1 / (2 * n - 1)If m a(k + 1) Thentemp = a(k)a(k) = a(k + 1)