VB上机考试 习题以及答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

VB上机考试

1、利用随机函数产生25个100到999之间的整数,构成5 5的矩阵,输出该矩阵。Dim a(1 To 5, 1 To 5)

Private Sub Form_Click()

Randomize

For i = 1 To 5

For j = 1 To 5

a(i, j) = Int(Rnd * (999 - 100 + 1) + 100)

Print a(i, j);

Next j

Print

Next i

End Sub

2、利用随机函数产生25个10到99之间的整数,求其平均值(要求保留3位小数,第4位四舍五入)。Private Sub Form_Click()

For i = 1 To 25

a = Int(Rnd * (99 - 10 + 1) + 10)

Print a;

s = s + a

Next i

Print

Avg = s / 25

Print Avg

End Sub

3、在窗体上按下鼠标的右键,记录其坐标。

Private Sub Form_Load() Label1.BorderStyle = 1

Label1.Alignment = 2

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 2 Then

Label1.Caption = X & "," & Y

End If

End Sub

4、利用随机函数产生25个10到99之间的整数,按从小到大的顺序显示。Dim a(1 To 25)

Private Sub Form_Click()

Cls

For i = 1 To 25

a(i) = Int(Rnd * (99 - 10 + 1) + 10)

Print a(i);

Next i

Print

For i = 1 To 25 - 1

For j = 1 To 25 - i

If a(j) > a(j + 1) Then tmp = a(j): a(j) = a(j + 1): a(j + 1) = tmp Next j

Next i

For i = 1 To 25

Print a(i);

Next i

End Sub

5、利用随机函数产生50个 [1,6] 之间的整数, 分别统计出1的个数,2的个数,3的个数,4的个数,5的个数和6的个数。Dim a(1 To 6)

Private Sub Form_Click()

For i = 1 To 6

a(i) = 0

Next i

For j = 1 To 50

x = Int(Rnd * (6 - 1 + 1) + 1)

a(x) = a(x) + 1

Next j

For i = 1 To 6

Print i & "出现了" & a(i); "次"

Next i

End Sub

6、在文本框中输入一些英语单词,统计空格的个数。

Dim n%, x As String, s% Private Sub Form_Click()

n = Len(Text1.Text)

x = Text1.Text

For i = 1 To n

If Mid(x, i, 1) = " " Then s = s + 1

Next i

Print "共出现了" & s & "个空格"

End Sub

7、编程计算下列公式的值,其中n (<10)为从键盘输入的正整数。

S=1!+3!+5!+……+(2*n-1)!Private Sub Form_Click()

n = Val(InputBox("请输入一个不大于10的整数"))

s = 0

For i = 1 To 2 * n - 1 Step 2

p = 1

For j = 1 To i

p = p * j

Next j

s = s + p

Next i

Print s

End Sub

8、编程计算下列公式的值,其中n (<10)为从键盘输入的正整数。

S=2!+4!+6!+……+(2*n)!Private Sub Form_Click()

n = Val(InputBox("请输入一个不大于10的整数"))

s = 0

For i = 2 To 2 * n Step 2

p = 1

For j = 1 To i

p = p * j

Next j

s = s + p

Next i

Print s

End Sub

9、用For …Next语句编程,双击窗体后,在屏幕上显示如图:

Private Sub Form_Click()

a = 0

For i = 1 To 3

Print Tab(8 - 2 * i - 1);

For j = 1 To 2 * i - 1

a = a + 1

Print Str(a);

Next j

Print

Next i

End Sub

10、用For …Next语句编程,双击窗体后,在屏幕上显示如图:

Private Sub Form_DblClick()

For i = 1 To 3

Print Tab(11 - 3 * i);

For j = 2 To 10 Step 2

Print j;

Next j

Print

Next i

End Sub

11、用For …Next语句编程,双击窗体后,在屏幕上显示如图:

Private Sub Form_Click()

For i = 1 To 3

x = 2 * i + 1

Print Tab(10 - 3 * i);

For j = 1 To 5

Print x;

Next j

Print

Next i

相关文档
最新文档