VB考试复习题

数本身)

Private Sub Form_Click()

Print \之间所有的水仙花数为:\ Dim x%, a%, b%, c% For x = 100 To 500 a = x Mod 10

b = (x Mod 100) \\ 10 c = x \\ 100

If x = a ^ 3 + b ^ 3 + c ^ 3 Then Print x Next x End Sub

3、输入一系列字符串,编程求出长度最大的字符串并输出其所对应的次序 Private Sub Form_Click()

Dim a(5) As String, b(4) As Integer, t%, max%, imax% For i = 1 To 5

a(i) = InputBox(\ Next i

For i = 0 To 4

b(i) = Len(Trim(a(i))) Next i max = 1 For i = 0 To 4

If max

Print \ Print \End Sub

4、输入一系列字符串,将字符串按递减次序排列。请编程实现 Dim a() As String, n%, i%, j% Private Sub Command1_Click() n = Val(Text1)

ReDima(n) As String

For i = LBound(a) To UBound(a)

a(i) = InputBox(\请输入字符串\Picture1.Print a(i); Spc(1); Next i End Sub

Private Sub Command2_Click() For i = 0 To n For j = 0 To n - 1

If a(j) < a(j + 1) Then t = a(j): a(j) = a(j + 1): a(j + 1) = t Next j

Next i

For i = 0 To n

Picture2.Print Tab(3); a(i); Spc(1) Next i End Sub

5.随机产生30~100(包括30、100)中的十个正整数,求最大值、最小值、平均值,并显示整个数组的值和结果。 Private Sub Form_Click()

Dim a(1 To 10) As Integer, i%, maxa%, mina%, avera! For i = 1 To 10

a(i) = Int(Rnd * 71 + 30) Next i

mina = a(1) maxa = a(1) avera = a(1) For i = 2 To 10

If a(i) >maxa Then maxa = a(i) If a(i) < mina Then mina = a(i) avera = avera + a(i) Next i

For i = 1 To 10 Print a(i); Next i Print

Print \End Sub 6、定义三个4×4的二维数组A,B,C,A和B中的元素均随机生成,数组A的范围是1~20,数组B的范围是100~200,数组C是A和B相乘得到的。请编程生成并输出A,B,C。 Private Sub Form_Click()

Dim a%(1 To 4, 1 To 4), b%(1 To 4, 1 To 4), c%(1 To 4, 1 To 4) Print \数组A\ For i = 1 To 4 For j = 1 To 4

a(i, j) = Int(Rnd * 20 + 1) Print Tab(j * 4); a(i, j); Next j Print Next i

Print \数组B\ For i = 1 To 4 For j = 1 To 4

b(i, j) = Int(Rnd * 100 + 100)

Print Tab(j * 6); b(i, j); Next j Print Next i

'Print \数组C\ 'For i = 1 To 4 'For j = 1 To 4 'c(i, j) = b(i, j) * a(i, j) 'Print Tab(j * 4); c(i, j); 'Next j 'Print 'Next i

Print \数组C\ For i = 1 To 4 For j = 1 To 4 c(i, j) = b(i, j) * a(i, j) Print Tab(j * 6); c(i, j); Next j Print Next i End Sub

7、随机产生15个小写字母,放在字符串中。(提示:c=chr(int(rnd*26+97))) Private Sub Form_Click() Dim a$(1 To 15), i%

Print \字符数组为a(i):\ For i = 1 To 15

a(i) = Chr(Int(Rnd * 26 + 97)) Print a(i); Spc(1); Next i Print End Sub

Private Sub Form_Load() FontSize = \End Sub 8、利用随机函数生成一个4×4的矩阵(即二维矩阵),范围是[20,50]内的整数,求它的两条对角线上元素之和。

Private Sub Command1_Click() Dim a%(3, 3), i%, j%, sum% For i = 0 To 3 For j = 0 To 3

a(i, j) = Int(Rnd * 31 + 20) Picture1.Print a(i, j); \

Next j

Picture1.Print Next i sum = 0 For i = 0 To 3

sum = sum + a(i, i) + a(i, 3 - i) Next i

Text1 = sum End Sub

9、有10个评委对歌手进行打分(分数存放在A数组中)要求编程计算歌手平均得分(按去掉一个最高分和一个最低分的计算办法计算)。 Private Sub Form_Click()

Dim a(), max%, min%, imax%, imin%, s!

a = Array(98, 97, 95, 91, 90, 99, 93, 94, 93, 96) n = UBound(a) For i = 0 To n Print a(i); Next i Print

min = a(0): imin = 0 For i = 0 To n

If a(i) < min Then min = a(i): imin = i Next i

Print \ For i = imin + 1 To n a(i - 1) = a(i) Next i

ReDim Preserve a(n - 1) For i = 0 To n - 1 Print a(i); Next i Print

For i = 0 To n - 1

If a(i) > max Then max = a(i): imax = i Next i

Print \ReDim Preserve a(n - 2) s = 0

For i = 0 To n - 2 s = s + a(i) Print a(i); Next i Print

Print \End Sub

10、随机产生15个大写字母,放在字符数组中。提示:c=chr(int(rnd*26+65)) Private Sub Form_Click() Dim a(1 To 15) As String For i = 1 To 15

a(i) = Chr(Int(Rnd * 26 + 65)) Print Tab(i * 2); a(i); Next i End Sub

11.编程输出n行杨辉三角形图,n由键盘输入。 Private Sub Command1_Click() Dim n%, i%, j% n = Val(Text1)

Dim a%(1 To 1000, 1 To 1000) For i = 1 To n a(i, 1) = 1 Next i

For i = 1 To n a(i, i) = 1 Next i

For j = 2 Toi - 1 For i = 3 To n

a(i, j) = a(i - 1, j - 1) + a(i - 1, j) Next i

Picture1.Print ; Next j

Picture1.Print Tab(j * n); a(i, j) For i = 1 To n For j = 1 Toi

Picture1.Print a(i, j); \Next j

Picture1.Print Next i End Sub

12、编写一个判断素数的通用过程(函数或子程序)。调用该过程,计算并输出区间[1000,1100]内所有素数的和。(提示:只能被1和自身整除的自然数称为素数。) Private Sub Picture1_Click() Dim i%, avera avera = 0

For i = 1000 To 1100

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4