1、常见VB考试题型1输入半径,求圆面积和球体积。Private Sub Form_Load()Dim r As Single, s As Single, v As Singler = InputBox(请输入半径r:, 输入数据)s = 3.14 * r 2v = 4 / 3 * r 3 * 3.14Print 圆面积为:; sPrint 球体积为:; vMsgBox (圆面积为: & s & Space(2) & 球体积为: & v)End Sub2输入两个数存放在x和y中 ,比较大小,保证大数放在x中,小的数放在Y中。Private Sub Command1_Click()Print 比较前
2、:X = InputBox(请输入X)Y = InputBox(请输入Y)Print X=; X, Y=; YIf X Y Then Z = Y Y = X X = ZEnd If Print 比较后:Print X=; X, Y=; YEnd Sub3 判断一个整数的奇偶性Private Sub Form_Click()x = Val(InputBox(请输入一个数;)If x Mod 2 = 0 Then MsgBox (x & 是偶数)Else MsgBox (x & 是奇数)End IfEnd Sub4 帐号和密码Private Sub Command1_Click()If Text1
3、.Text = 12345 Then If Text2.Text = 12345 Then MsgBox 登录成功, 64 + 1, 登录 Else MsgBox 密码错误,请重新输入, 16 End IfElse MsgBox 用户不存在, 16 + 1, 登录End IfEnd Sub5 判断一个数是整数还是小数,如果是整数再判断其奇偶性 。 Private Sub Form_Click()x = InputBox(请输入一个数;)If InStr(1, x, .) = 0 Then If x Mod 2 = 0 Then MsgBox (x & 是整数,是偶数!) Else MsgBox
4、 (x & 是整数,是奇数!) End IfElse MsgBox (x & 是小数)End IfEnd Sub6 书店优惠售书Private Sub Command1_Click()Dim x As Single, y As Singlex = Val(Text1.Text)Select Case x Case Is = 100 y = x * 0.8 Case Is = 200 y = x * 0.7 Case Is = 300 y = x * 0.5 Case Else y = x * 0.3End SelectLabel3.Caption = y & 元End Sub7 设计一个计程车
5、收费程序Private Sub Command1_Click()X = Val(Text1.Text)Select Case X Case Is = 3 Label3.Caption = 6 Case Is = 30 Label3.Caption = 6 + (X - 3) * 1.5 Case Else Label3.Caption = 6 + 27 * 1.5 + (X - 30) * 2End SelectEnd Sub8 输入10个数,输出累加之和。Private Sub Command1_Click()Dim S As Single, i As Integer, x As Singl
6、eS = 0For i = 1 To 10x = Val(InputBox(请输入第 & i & 个数)Print 第 & i & 个数 & xS = S + xNext iPrint 十个数累加之和为 & SEnd Sub9 输入10个数,输出偶数之和。Private Sub Command1_Click()Dim S As Single, x As SingleDim n As Integer, i As IntegerS = 0For i = 1 To 10x = Val(InputBox(请输入第 & i & 个数)Print 第 & i & 个数 & xIf x Mod 2 = 0
7、ThenS = S + Val(x)End IfNext iPrint 十个数中偶数累加之和为 & SEnd Sub10 求S=1+2+3+100Private Sub Command1_Click()Dim I As Integer, S As LongS = 0For I = 1 To 100S = S + INext IPrint Tab(10); S=; SEnd Sub11 求S=1+3+5+99Private Sub Command1_Click()s = 0For i = 1 To 100 Step 2 s = s + iNext iPrint s=; sEnd Sub12 S=
8、1+22+32+102,计算并输出sPrivate Sub Command1_Click()s = 0For i = 1 To 10 s = s + i 2Next iPicture1.Print s=; sEnd Sub13 S=1+22+32+n2,问n为多少时,s的值大于100000?Private Sub Command1_Click()s = 0n = 0Do While s 10 (-5) S1 = 1 J = 1 Do While J = 10 (-5)S = S + (1 / x) * (-1) (n + 1)x = x * (n * 2) * (2 * n + 1)n = n
9、 + 1LoopPrint S=; SEnd Sub21 s=2+22+222+2222+22222+222222Private Sub Command1_Click()Dim s As Long, s1 As Long, i As Integer, j As Integers = 0For i = 1 To 6 s1 = 0 For j = 1 To i s1 = s1 + 2 * 10 (j - 1) Nexts = s + s1Next Print s=; sEnd Sub22 S=a+aa+aaa+aaaa(N个a)其中a是一个1,9的随机整数,N是一个5,10的随机整数。Privat
10、e Sub Command1_Click()Dim a As Integer, n As IntegerDim s As Long, s1 As Long, i As Integer, j As IntegerClsRandomizea = Int(9 * Rnd) + 1n = Int(6 * Rnd) + 5s = 0For i = 1 To n s1 = 0 For j = 1 To i s1 = s1 + a * 10 (j - 1) Next j s = s + s1Next i Print 当a=; a, n=; n; 时 Print Print s=; sEnd Sub23 S=
11、1+12+123+1234+12345+123456Private Sub Command1_Click()Dim s As Long, s1 As Long, i As Integer, j As Integers = 0s1 = 0For i = 1 To 6s1 = s1 * 10 + iPrint s1s = s + s1Next iPrint s=; ss = 0For i = 1 To 6 s1 = 0 For j = 1 To i s1 = s1 + j * 10 (i - j) Next j s = s + s1Next iPrint s=;sEnd Sub24 将一字符串逆序
12、输出Private Sub Command1_Click()Dim n As Integer, s1 As String, s2 As Strings1 = Text1.Texts2 = n = Len(Trim(Text1.Text)For i = n To 1 Step -1 s2 = s2 & Mid(s1, i, 1)Next iText2.Text = s2End Sub25 判断任给一大于3的整数是否是素数。Private Sub Command1_Click()Dim N As Integer, I As IntegerN = InputBox(请输入一个大于3的整数)For I
13、 = 2 To N - 1 If N Mod I = 0 Then Exit For End IfNext IIf N = I Then MsgBox (N & 是素数)Else MsgBox (N & 不是素数)End IfEnd Sub26 输出3100之间的素数输出Private Sub Command1_Click()Dim n As Integer, i As IntegerFor n = 3 To 100 For i = 2 To n - 1 If n Mod i = 0 Then Exit For End If Next i If i = n Then Print n End I
14、fNext nEnd Sub换行输出Private Sub Command2_Click()Dim n As Integer, i As IntegerDim m As Integerm = 0For n = 3 To 100 For i = 2 To n - 1 If n Mod i = 0 Then Exit For End If Next i If i = n Then m = m + 1 If m Mod 5 = 0 Then Print n Else Print n; End If End IfNext nEnd SubPrivate Sub Command2_Click()Dim
15、n As Integer, i As Integerdim m as inm = 0For n = 3 To 100 For i = 2 To n - 1 If n Mod i = 0 Then Exit For End If Next i If i = n Then m = m + 1 If m Mod 5 = 0 Then Print Tab(6 * m); n m = 0 Else Print Tab(6 * m); n; End If End IfNext nEnd Sub27 输出100999之间的水仙花数Private Sub Command1_Click()Dim I As In
16、teger, A As IntegerDim B As Integer, C As IntegerFor I = 100 To 999 A = Int(I / 100) B = Int(I / 10) - A * 10 C = I - A * 100 - B * 10 If A 3 + B 3 + C 3 = I Then Picture1.Print I; End IfNext IEnd Sub28陈婷的QQ密码是一个5位数。但因为有一段比较长的日子没上了,陈婷把这个密码给忘了。不过陈婷的生日是8月1日,她妈妈的生日是9月1日,她特别喜欢把同时是8l和9l的倍数用作密码。陈婷还记得这个密码的
17、中间一位(百位数)是l。你能设计一个程序帮她找回这个密码吗? Private Sub Command1_Click()陈婷密码:5位数,能被81,91整除,百位是1Dim i As Long, x As IntegerFor i = 10100 To 99199 x = i 100 Mod 10 If x = 1 Then If i Mod 91 = 0 And i Mod 81 = 0 Then MsgBox 密码是 & i End If End IfNext iEnd Sub29 百元买百鸡问题。假定小鸡每只5角,公鸡每只2元,母鸡每只3元。现在有100元钱要求买100只鸡(每种鸡至少一只
18、),编程列出所有可能的购鸡方案Option ExplicitPrivate Sub Command1_Click()Dim X As Integer, Y As IntegerDim z As Integer, I As IntegerI = 0For X = 1 To 100 For Y = 1 To 50 For z = 1 To 33 If X + Y + z = 100 And 0.5 * X + 2 * Y + 3 * z = 100 Then I = I + 1 Picture1.Print 方案 & I & :小鸡 & X & 只, _ & 公鸡 & Y & 只, & 母鸡 &
19、z & 只。 End IfNext z, Y, XEnd Sub30 鸡兔合笼共20只,脚46只问鸡几只?兔几只?Private Sub Command1_Click()Dim x As Integer, y As IntegerFor x = 1 To 20 For y = 1 To 20 - x If x + y = 20 And 2 * x + 4 * y = 46 Then Print 鸡 & x & 只 , 兔 & y & 只 End IfNext yNext xEnd Sub31 找出100之内的自然数对 。 (两数的和是某个自然数的平方,两数的差也是某数的平方)Private S
20、ub Command1_Click()For i = 1 To 99 For j = i + 1 To 100 If Int(Sqr(j - i) = Sqr(j - i) And Int(Sqr(j + i) = Sqr(j + i) Then Print i, j End If Next j Next iEnd Sub32 找出1000-9999之间的玫瑰花数。Private Sub Command1_Click()Dim i As IntegerDim a1 As Integer, a2 As IntegerDim a3 As Integer, a4 As IntegerFor i =
21、1000 To 9999 a1 = i 1000 a2 = i 100 Mod 10 a3 = i 10 Mod 10 a4 = i Mod 10 If a1 4 + a2 4 + a3 4 + a4 4 = i Then Print i End IfNext iEnd Sub33 猴子吃桃子。小猴在某天摘桃若干个,当天吃掉一半多一个;第二天吃了剩下的桃子的一半多一个;以后每天都吃尚存桃子的一半多一个,到第7天要吃时只剩下一个,问小猴共摘下了多少个桃子?Option ExplicitPrivate Sub Command1_Click()Dim X As Integer, I As Integ
22、erX = 1For I = 6 To 1 Step -1X = (X + 1) * 2Picture1.Print 第 & I; 天桃子数是: & X & 个。Next IEnd Sub34瓜农有西瓜1020个,每天能卖掉前一天剩下的总数的一半还多两个,问多少天能卖完。Option ExplicitPrivate Sub Command1_Click()Dim X As Integer, I As IntegerX = 1020I = 0 Do While X 0 X = X / 2 - 2 I = I + 1 LoopLabel4.Caption = 第 & I & 天能卖完.End Su
23、b35一球从10米高空落下,每次弹起高度为落下高度的40%,求第8次落下,小球经历的路程。Private Sub Command1_Click()Dim s As Single, h As Single, i As Integers = 10h = 10For i = 2 To 8 h = h * 0.4 s = s + h * 2 Next iPicture1.Print 球第八次落下经历的路程是:; s; 米End Sub36 输入十个数,输出其中的最大数和最小数Private Sub Command1_Click()Dim x As Single, i As IntegerDim max As Single, min As Singlex = Val(InputBox(请输入第1个数)Print xmax = x: min = xFor i = 2 To 10 x = Val(InputBox(请输入第 &
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1