最新VB经典例题13道(附答案)

上传人:人*** 文档编号:510629946 上传时间:2023-10-25 格式:DOCX 页数:7 大小:14.27KB
返回 下载 相关 举报
最新VB经典例题13道(附答案)_第1页
第1页 / 共7页
最新VB经典例题13道(附答案)_第2页
第2页 / 共7页
最新VB经典例题13道(附答案)_第3页
第3页 / 共7页
最新VB经典例题13道(附答案)_第4页
第4页 / 共7页
最新VB经典例题13道(附答案)_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《最新VB经典例题13道(附答案)》由会员分享,可在线阅读,更多相关《最新VB经典例题13道(附答案)(7页珍藏版)》请在金锄头文库上搜索。

1、如有侵权请联系网站删除,仅供学习交流VB经典例题13道(附答案)L一串字符求有多少字母,有多少数字,有多少其他Private Sub Button l_Click(ByVal sender As System.Object, By Vai e AsSystem.EventArgs) Handles Button 1.ClickDim s, c, q, w, rs = TextBoxl.TextFor i = 1 To LeMs)c = Mid(s, i, 1)If UCase(c) = nAH And UCase(c) = n0H And c = n9H Thenw = w + 1Elser

2、= r + 1End IfNextLabell.Text = 字母有“ &q& ”个 数字有“ & w & ”个 其他有“ & r & ”个“End Sub2.一串字符以?结尾,求有多少字母,有多少数字,有多少其他Private Sub Button 1 _Click(B yV al sender As System.Object, By Vai e AsSystem.EventArgs) Handles Button 1.ClickDim s, a, z, x, c, is = TextBoxl.Texta = Mid(s, 1, 1)i= 1Do While a ?If UCase(a)

3、= nAn And UCase(a) = 0 And a = 0 ThenLabel 1 .Text = 是“ & Len(c) & ”位数”ElseLabel 1 .Text = 是& Len(c) - 1 & ”位数”End IfElseIf c = 0 ThenFor i = 1 To Len(c)If Mid(c, i, = Then Exit For j=j+lNextLabel 1.Text = 小数点前有“ & j & “位数& ”小数点后有” & Len(c) - j-1 & ”位数ElseFor i = 1 To Len(c)If Mid(c, i, 1) = Then Ex

4、it For j=j+lNextLabel 1.Text = 小数点前有” & j - 1 & “位数” & “小数点后有 & Len(c)位数End IfEnd IfEnd Sub 1111_ 71-4十 ZZ 4 .求圆周率公式1 3 5 74Private Sub Button l_Click(ByVaI sender As System.Object, By Vai e AsSystem.EventArgs) Handles Button 1.ClickDim a, s, n, pia = 1n = 1While Math.Abs(l /n) 0.0001pi = pi + a * (

5、1 / n)n = n + 2 a = -aEnd WhileLabel LText = 4 * piEnd Sub5 .求自然对数 e 公式 e=l+l+l/2!+l/3!+.+l/n!+.Private Sub Button 1 _Click(ByVai sender As System.Object, ByVai e AsSy stem. Event Args) Handles Button 1.ClickDim n, el, 1n = 1el = 1While 1 / n0.011= 1For i = 1 To nl = l*iNextn = n + 1el =el + 1/1End

6、WhileLzabel LText = elEnd Sub6 .右直角三角形Private Sub Buttonl_Click(ByVal sender As System.Object, ByVai e As System.EventArgs) Handles Button 1.ClickDim n, sLabel LText =n = Val(TextBox LText)For i = 1 To ns =Label LText &= Space(n - i)For j = 1 To is &= 1*NextLabel 1 .Text &= s & vbCrLfNextEnd Sub7 .等

7、腰三角形Private Sub Button l_CIick(ByVal sender As System.Object, By Vai e As System.EventArgs) Handles Button 1.ClickDim n, sLabelLText 二”n = Val(TextBox LText)For i = 1 To n_ ”,S =Label 1.Text &= Space(n - i)For j = 1 To 2 * i - 1s &=NextLabel 1 .Text &= s & vbCrLfNextEnd Sub8 .倒等腰三角形Private Sub Butto

8、n l_CIick(ByVal sender As System.Object, By Vai e AsSystem.EventArgs) Handles Button 1.ClickDim n, sLabel 1.Text =,Hn = Val(TextBox l.Text)For i = n To 1 Step -1_ H VI s =Labell.Text &= Space(n - i)For j = 2 * i - 1 To 1 Step -1 s &=NextLabell.Text &= s & vbCrLfNextEnd Sub9 .右上角的直角三角形Private Sub But

9、ton l_Click(ByVal sender As System.Object, By Vai e AsSystem.EventArgs) Handles Button 1.ClickDim n, sLabell.Text = n = Val(TextBox 1 .Text)For i = n To 1 Step -1_ HVI s =Label 1 .Text &= Space(n - i)For j = i To 1 Step -1s &=NextLabel 1 .Text &= s & vbCrLfNextEnd Sub10 .菱形Private Sub Buttonl_Click(

10、ByVal sender As System.Object, ByVai e AsSystem.EventArgs) Handles Button 1.ClickDim n, sLabell.Text = For i = 1 To 6s =Label 1.Text &= Space(i - 1)For j = 1 To 12s &=NextLabel 1.Text &= s & vbCrLfNextEnd Sub11 .水仙花数字三位数字的个位数字的立方和等于该数字本身(1) .判断输入的数字是否是水仙花数Private Sub Button l_Click(ByVal sender As S

11、ystem.Object, By Vai e As System.EventArgs) Handles Button 1.ClickDini s, a, b, cs = Val(TextBox 1 .Text)Labell.Text = a = s 100b = (s-a* 100) 10c = s Mod 10IfaA3 + bA3 + cA3 = s ThenLabel 1 .Text &= s & ”是水仙花数”ElseLabel 1 .Text &= s & 不是水仙花数”End IfEnd Sub(2) .找出所有的水仙花数Private Sub Button l_Click(ByV

12、al sender As System.Object, By Vai e As System.EventArgs) Handles Button 1.ClickDim s, a, b, cLabel 1 .Text = 水仙花数是 & vbCrLfFor s = 100 To 999a = s 100b = (s-a* 100) 10c = s Mod 10IfaA3 + bA3 + cA3 = s ThenLabel 1.Text &= s & vbCrLfEnd IfNextEnd Sub12.完全数正整数的因数之和等于这个数(1) .判断输入的数字是不是完全数Private Sub Bu

13、tton l_Click(ByVal sender As System.Object, By Vai e As System.EventArgs) Handles Button 1.ClickDim s, j, 1, a(100)s = Val(TextBox l.Text)j = 1For i = 1 To s - 1If s Mod i = 0 Thena(j) = ij=j + lEnd IfNextFor i = 1 To j1 = 1 + a(i)NextIf 1 = s ThenLabel 1 .Text = s & ”是完全数”ElseLabel 1 .Text = s & 不是完全数”End IfEnd Sub(2) .找出1到n内的完全数、n由用户输入Private Sub Button l_Click(ByVal sender As System.Object, By Vai e As Sy stem. Event Args) Handles Button 1.ClickDim nJn = Val(TextBox l.Text)Labell.Text = nFor p

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

当前位置:首页 > 生活休闲 > 网络生活

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号