欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    VB经典例题13道(附答案)(15页).doc

    • 资源ID:35028585       资源大小:36.50KB        全文页数:16页
    • 资源格式: DOC        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    VB经典例题13道(附答案)(15页).doc

    -1.一串字符求有多少字母,有多少数字,有多少其他Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s, c, q, w, r s = TextBox1.Text For i = 1 To Len(s) c = Mid(s, i, 1) If UCase(c) >= "A" And UCase(c) <= "Z" Then q = q + 1 ElseIf c >= "0" And c <= "9" Then w = w + 1 Else r = r + 1 End If Next Label1.Text = "字母有" & q & "个 数字有" & w & "个 其他有" & r & "个" End Sub2.一串字符以?结尾,求有多少字母,有多少数字,有多少其他Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s, a, z, x, c, i s = TextBox1.Text a = Mid(s, 1, 1) i = 1 Do While a <> "?" If UCase(a) >= "A" And UCase(a) <= "Z" Then z = z + 1 ElseIf a >= "0" And a <= "9" Then x = x + 1 Else c = c + 1 End If i = i + 1 a = Mid(s, i, 1) Loop Label1.Text = z & x & c End Sub3.给定一个数字求它是几位数字,如(1).12345 (2).-12345 (3).123.45Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s, c, j s = TextBox1.Text c = Trim(Str(s) If Int(c) = c Then If c >= 0 Then Label1.Text = "是" & Len(c) & "位数" Else Label1.Text = "是" & Len(c) - 1 & "位数" End If Else If c >= 0 Then For i = 1 To Len(c) If Mid(c, i, 1) = "." Then Exit For j = j + 1 Next Label1.Text = "小数点前有" & j & "位数 " & " 小数点后有" & Len(c) - j - 1 & "位数 " Else For i = 1 To Len(c) If Mid(c, i, 1) = "." Then Exit For j = j + 1 Next Label1.Text = "小数点前有" & j - 1 & "位数 " & " 小数点后有" & Len(c) - j - 1 & "位数 " End If End If End Sub4.求圆周率 公式Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a, s, n, pi a = 1 n = 1 While Math.Abs(1 / n) > 0.0001 pi = pi + a * (1 / n) n = n + 2 a = -a End While Label1.Text = 4 * pi End Sub5.求自然对数e 公式e=1+1+1/2!+1/3!+1/n!+.Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim n, e1, l n = 1 e1 = 1 While 1 / n > 0.01 l = 1 For i = 1 To n l = l * i Next n = n + 1 e1 = e1 + 1 / l End While Label1.Text = e1End Sub6.右直角三角形 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim n, s Label1.Text = "" n = Val(TextBox1.Text) For i = 1 To n s = "" Label1.Text &= Space(n - i) For j = 1 To i s &= "*" Next Label1.Text &= s & vbCrLf Next End Sub7等腰三角形 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim n, s Label1.Text = "" n = Val(TextBox1.Text) For i = 1 To n s = "" Label1.Text &= Space(n - i) For j = 1 To 2 * i - 1 s &= "*" Next Label1.Text &= s & vbCrLf Next End Sub8倒等腰三角形Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim n, s Label1.Text = "" n = Val(TextBox1.Text) For i = n To 1 Step -1 s = "" Label1.Text &= Space(n - i) For j = 2 * i - 1 To 1 Step -1 s &= "*" Next Label1.Text &= s & vbCrLf Next End Sub9右上角的直角三角形Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim n, s Label1.Text = "" n = Val(TextBox1.Text) For i = n To 1 Step -1 s = "" Label1.Text &= Space(n - i) For j = i To 1 Step -1 s &= "*" Next Label1.Text &= s & vbCrLf Next End Sub10菱形Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim n, s Label1.Text = "" For i = 1 To 6 s = "" Label1.Text &= Space(i - 1) For j = 1 To 12 s &= "*" Next Label1.Text &= s & vbCrLf Next End Sub11.水仙花数字 三位数字的个位数字的立方和等于该数字本身(1).判断输入的数字是否是水仙花数Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s, a, b, c s = Val(TextBox1.Text) Label1.Text = "" a = s 100 b = (s - a * 100) 10 c = s Mod 10 If a 3 + b 3 + c 3 = s Then Label1.Text &= s & "是水仙花数" Else Label1.Text &= s & "不是水仙花数" End If End Sub(2).找出所有的水仙花数Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s, a, b, c Label1.Text = "水仙花数是" & vbCrLf For s = 100 To 999 a = s 100 b = (s - a * 100) 10 c = s Mod 10 If a 3 + b 3 + c 3 = s Then Label1.Text &= s & vbCrLf End If Next End Sub12.完全数 正整数的因数之和等于这个数(1).判断输入的数字是不是完全数Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s, j, l, a(100) s = Val(TextBox1.Text) j = 1 For i = 1 To s - 1 If s Mod i = 0 Then a(j) = i j = j + 1 End If Next For i = 1 To j l = l + a(i) Next If l = s Then Label1.Text = s & "是完全数" Else Label1.Text = s & "不是完全数" End If End Sub(2).找出1到n内的完全数,n 由用户输入Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim n, j n = Val(TextBox1.Text) Label1.Text = "" For p = 2 To n j = 0 For i = 1 To p - 1 If p Mod i = 0 Then j = j + i End If Next If j = p Then Label1.Text &= p & " " End If Next End Sub13.显示1,1,2,3,5,8,13,21 F(i)=f(i-1)+ f(i-2)Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim f(30) f(1) = 1 f(2) = 1 For i = 3 To 30 f(i) = f(i - 1) + f(i - 2) Next Label1.Text = "" For i = 1 To 30 Label1.Text &= f(i) & "," If i Mod 6 = 0 Then Label1.Text &= vbCrLf Next End Sub第 16 页-

    注意事项

    本文(VB经典例题13道(附答案)(15页).doc)为本站会员(1595****071)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开