2022年常见VB考试题型.pdf
《2022年常见VB考试题型.pdf》由会员分享,可在线阅读,更多相关《2022年常见VB考试题型.pdf(32页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、常见 VB考试题型1 输入半径 ,求圆面积与球体积。Private Sub Form_Load() Dim r As Single, s As Single, v As Single r = InputBox( 请输入半径r:, 输入数据 ) s = 3、14 * r 2 v = 4 / 3 * r 3 * 3 、14 Print 圆面积为 :; s Print 球体积为 :; v MsgBox ( 圆面积为 : & s & Space(2) & 球体积为 : & v) End Sub 2 输入两个数存放在x 与 y 中 ,比较大小 ,保证大数放在x 中,小的数放在Y 中。Private Su
2、b Command1_Click() Print 比较前 : X = InputBox( 请输入 X) Y = InputBox( 请输入 Y) Print X=; X, Y=; Y If X Y Then Z = Y Y = X X = Z End If Print 比较后 : Print X=; X, Y=; Y End Sub 3 判断一个整数的奇偶性Private Sub Form_Click() x = Val(InputBox( 请输入一个数 ;) If x Mod 2 = 0 Then MsgBox (x & 就是偶数 ) Else MsgBox (x & 就是奇数 ) End
3、If End Sub 4 帐号与密码Private Sub Command1_Click() If Text1、Text = 12345 Then If Text2 、Text = 12345 Then MsgBox 登录成功 , 64 + 1, 登录 Else MsgBox 密码错误 ,请重新输入 , 16 End If Else MsgBox 用户不存在 , 16 + 1, 登录 End If 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 1 页,共 32 页 - - - - - - - - - -
4、 常见 VB考试题型End Sub 5 判断一个数就是整数还就是小数,如果就是整数再判断其奇偶性。Private Sub Form_Click() x = InputBox( 请输入一个数 ;) If InStr(1, x, 、) = 0 Then If x Mod 2 = 0 Then MsgBox (x & 就是整数 ,就是偶数! ) Else MsgBox (x & 就是整数 ,就是奇数! ) End If Else MsgBox (x & 就是小数 ) End If End Sub 6 书店优惠售书Private Sub Command1_Click() Dim x As Single
5、, y As Single x = 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 、3 End Select Label3、Caption = y & 元 End Sub 7 设计一个计程车收费程序Private Sub Command1_Click() X = Val(Text1 、Text) Select Case X Case Is = 3 Label3、Caption =
6、 6 Case Is = 30 Label3、Caption = 6 + (X - 3) * 1 、5 Case Else Label3、Caption = 6 + 27 * 1 、5 + (X - 30) * 2 End Select End Sub 8 输入 10 个数 ,输出累加之与。Private Sub Command1_Click() 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 2 页,共 32 页 - - - - - - - - - - 常见 VB考试题型Dim S As Single,
7、 i As Integer, x As Single S = 0 For i = 1 To 10 x = Val(InputBox( 请输入第 & i & 个数) Print 第 & i & 个数 & x S = S + x Next i Print 十个数累加之与为 & S End Sub 9 输入 10 个数 ,输出偶数之与。Private Sub Command1_Click() Dim S As Single, x As Single Dim n As Integer, i As Integer S = 0 For i = 1 To 10 x = Val(InputBox( 请输入第
8、& i & 个数) Print 第 & i & 个数 & x If x Mod 2 = 0 Then S = S + Val(x) End If Next i Print 十个数中偶数累加之与为 & S End Sub 10 求 S=1+2+3+ +100Private Sub Command1_Click() Dim I As Integer, S As Long S = 0 For I = 1 To 100 S = S + I Next I Print Tab(10); S=; S End Sub 11 求 S=1+3+5+ +99 Private Sub Command1_Click()
9、 s = 0 For i = 1 To 100 Step 2 s = s + i Next i Print s=; s End Sub 12S=1+22+32+ +102,计算并输出sPrivate Sub Command1_Click() s = 0 For i = 1 To 10 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 3 页,共 32 页 - - - - - - - - - - 常见 VB考试题型s = s + i 2 Next i Picture1、Print s=; s End Sub
10、13 S=1+22+32+ +n2,问 n 为多少时 ,s 的值大于 100000?Private Sub Command1_Click() s = 0 n = 0 Do 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 + 1 Loop Print S=; S End Sub 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第
11、 6 页,共 32 页 - - - - - - - - - - 常见 VB考试题型21 s=2+22+222+2222+22222+222222Private Sub Command1_Click() Dim s As Long, s1 As Long, i As Integer, j As Integer s = 0 For i = 1 To 6 s1 = 0 For j = 1 To i s1 = s1 + 2 * 10 (j - 1) Next s = s + s1 Next Print s=; s End Sub 22 S=a+aa+aaa+ +aaaa(N 个 a)其中 a 就是一个
12、 1,9的随机整数 ,N 就是一个 5,10 的随机整数。Private Sub Command1_Click() Dim a As Integer, n As Integer Dim s As Long, s1 As Long, i As Integer, j As Integer Cls Randomize a = Int(9 * Rnd) + 1 n = Int(6 * Rnd) + 5 s = 0 For i = 1 To n s1 = 0 For j = 1 To i s1 = s1 + a * 10 (j - 1) Next j s = s + s1 Next i Print 当
13、a=; a, n=; n; 时 Print Print s=; s End Sub 23 S=1+12+123+1234+12345+123456Private Sub Command1_Click() Dim s As Long, s1 As Long, i As Integer, j As Integer s = 0 s1 = 0 For i = 1 To 6 s1 = s1 * 10 + i Print s1 s = s + s1 Next i 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 7 页
14、,共 32 页 - - - - - - - - - - 常见 VB考试题型Print s=; s s = 0 For i = 1 To 6 s1 = 0 For j = 1 To i s1 = s1 + j * 10 (i - j) Next j s = s + s1 Next i Print s=;s End Sub 24 将一字符串逆序输出Private Sub Command1_Click() Dim n As Integer, s1 As String, s2 As String s1 = Text1、Text s2 = n = Len(Trim(Text1、Text) For i =
15、 n To 1 Step -1 s2 = s2 & Mid(s1, i, 1) Next i Text2、Text = s2 End Sub 25 判断任给一大于3 的整数就是否就是素数。Private Sub Command1_Click() Dim N As Integer, I As Integer N = InputBox( 请输入一个大于3 的整数 ) For I = 2 To N - 1 If N Mod I = 0 Then Exit For End If Next I If N = I Then MsgBox (N & 就是素数 ) Else MsgBox (N & 不就是素数
16、 ) End If End Sub 26 输出 3100 之间的素数输出Private Sub Command1_Click() Dim n As Integer, i As Integer For n = 3 To 100 For i = 2 To n - 1 If n Mod i = 0 Then 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 8 页,共 32 页 - - - - - - - - - - 常见 VB考试题型Exit For End If Next i If i = n Then Pr
17、int n End If Next n End Sub 换行输出Private Sub Command2_Click() Dim n As Integer, i As Integer Dim m As Integer m = 0 For 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 If Next n End Sub Private Sub
18、 Command2_Click() Dim n As Integer, i As Integer dim m as in m = 0 For 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 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 9 页,共 32 页 - -
19、- - - - - - - - 常见 VB考试题型 Else Print Tab(6 * m); n; End If End If Next n End Sub 27 输出 100999 之间的水仙花数Private Sub Command1_Click() Dim I As Integer, A As Integer Dim B As Integer, C As Integer For 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
20、 Then Picture1、Print I; End If Next I End Sub 28 陈婷的 QQ 密码就是一个5 位数。但因为有一段比较长的日子没上了,陈婷把这个密码给忘了。不过陈婷的生日就是8 月 1 日,她妈妈的生日就是9 月 1 日,她特别喜欢把同时就是8l与 9l 的倍数用作密码。陈婷还记得这个密码的中间一位(百位数 )就是 l。您能设计一个程序帮她找回这个密码不? Private Sub Command1_Click() 陈婷密码 :5 位数 ,能被 81,91 整除 ,百位就是 1 Dim i As Long, x As Integer For i = 10100 T
21、o 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 If Next i End Sub 29百元买百鸡问题。假定小鸡每只5 角,公鸡每只 2 元,母鸡每只3 元。现在有100 元钱要求买 100 只鸡 (每种鸡至少一只),编程列出所有可能的购鸡方案Option Explicit Private Sub Command1_Click() Dim X As Integer, Y As Integer Dim z As Integer, I As
22、 Integer I = 0 For X = 1 To 100 For Y = 1 To 50 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 10 页,共 32 页 - - - - - - - - - - 常见 VB考试题型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 & 只, & 母
23、鸡 & z & 只。 End If Next z, Y, X End Sub 30 鸡兔合笼共20 只,脚 46 只问鸡几只 ?兔几只 ?Private Sub Command1_Click() Dim x As Integer, y As Integer For 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 If Next y Next x End Sub 31 找出 100 之内的自然数对。(两数的与就是某个自然数的平方,两数
24、的差也就是某数的平方 ) Private Sub 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 i End Sub 32 找出 1000-9999 之间的玫瑰花数。Private Sub Command1_Click() Dim i As Integer Dim a1 As Integer, a2 As Integer Dim a3 As
25、Integer, a4 As Integer For i = 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 If Next i 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 11 页,共 32 页 - - - - - - - - - - 常见 VB考试题型End Sub 33 猴子吃桃子。小猴在某天摘桃若
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022 常见 VB 考试 题型
限制150内