VB书后习题解答(苏大出版社)

更新时间:2023-10-27 05:41:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

第五章 选择分支与循环

1.阅读程序,写出执行结果。 (1) 6 55

(2)

运行结果为: DDEF

EDDEF FEDDEF

(3)

运行结果为: 6 5 (4)

运行结果为: 11 10 8

2.编写程序,随机生成100个两位整数,并统计出其中小于等于40、大于40且小于等于70及大于70的数据个数。

答:程序代码如下: Option Explicit

Private Sub Form_Click()

Dim i As Integer, x As Integer

1

Dim c1 As Integer, c2 As Integer, c3 As Integer For i = 1 To 100

x = Int(Rnd * 90) + 10 Print x;

If i Mod 10 = 0 Then Print If x <= 40 Then c1 = c1 + 1

ElseIf x <= 70 Then c2 = c2 + 1 Else

c3 = c3 + 1 End If Next i Print

Print \的数有:\ Print \且<=70的数有:\ Print \的数有:\End Sub

3.编写程序,求下面函数的值。

?2?x?x?2? y??2?x??25?xX≤0 05

Option Explicit

Private Sub Command1_Click() Text1.Text = \ Text2.Text = \ Text1.SetFocus End Sub

2

Private Sub Command2_Click() Dim x As Integer x = Val(Text1.Text) Select Case x Case Is > 5

Text2.Text = CStr(25 - x) Case Is > 2

Text2.Text = CStr(x ^ 2) Case Is > 0

Text2.Text = CStr(x + 2) Case Else

Text2.Text = CStr(2 - x) End Select End Sub

4.随机生成20个三位正整数,将其中的奇数和偶数分两行显示在窗体上。

答:程序代码如下: Option Explicit Option Base 1

Private Sub Form_Click()

Dim a(20) As Integer, i As Integer Print \生成的20个数如下:\ For i = 1 To 20

a(i) = Int(Rnd * 900) + 100 Print a(i);

If i Mod 10 = 0 Then Print Next i

For i = 1 To 20

If a(i) Mod 2 = 0 Then List2.AddItem a(i) Next i

For i = 1 To 20

If a(i) Mod 2 = 1 Then List1.AddItem a(i) Next i Print End Sub

3

5.

Private Sub Command1_Click() x = Val(Text1.Text) y = Val(Text2.Text) For i = x To x * y

If i Mod x = 0 And i Mod y = 0 Then Text3.Text = CStr(i) Exit For End If Next i End Sub

第六章 数 组1.

6 7 9 2 5 8 1 3 4

2. 一维数组对调

4

Option Explicit Option Base 1

Dim a(15) As Integer

Private Sub Command1_Click() Dim i As Integer Randomize For i = 1 To 15

a(i) = Int(Rnd * 100) + 1

Text1.Text = Text1.Text + Format(a(i), \Next i End Sub

Private Sub Command2_Click() Dim i As Integer, t As Integer For i = 1 To UBound(a) / 2 t = a(i)

a(i) = a(UBound(a) + 1 - i) a(UBound(a) - i + 1) = t Next i

For i = 1 To 15

Text2.Text = Text2.Text + Format(a(i), \Next i End Sub

Private Sub Command3_Click()

Text1.Text = \End Sub

Private Sub Command4_Click() Unload Me End Sub

5.求二维数组的行和与列和 Option Explicit Option Base 1

Dim a(4, 5) As Integer

Dim SumL As Integer, SumC As Integer Private Sub CmdArry_Click() Dim I As Integer, J As Integer

5

本文来源:https://www.bwwdw.com/article/bwn2.html

Top