经典的VB编程题.doc

上传人:11****ws 文档编号:3129678 上传时间:2019-05-22 格式:DOC 页数:20 大小:242.21KB
下载 相关 举报
经典的VB编程题.doc_第1页
第1页 / 共20页
经典的VB编程题.doc_第2页
第2页 / 共20页
经典的VB编程题.doc_第3页
第3页 / 共20页
经典的VB编程题.doc_第4页
第4页 / 共20页
经典的VB编程题.doc_第5页
第5页 / 共20页
点击查看更多>>
资源描述

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)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 精品笔记

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。