好文档 - 专业文书写作范文服务资料分享网站

VB程序设计教程(第3版)课后实验答案

天下 分享 时间: 加入收藏 我要投稿 点赞

x = InputBox(\ y = InputBox(\ z = InputBox(\

Print \ x y z\ Print \排序前\ \ \ If x < y Then t = x: x = y: y = t If x < z Then t = x: x = z: z = t If y < z Then t = y: y = z: z = t

Print \排序后\ \ \End Sub

Private Sub Command2_Click() Dim x!, y!, z!

x = InputBox(\ y = InputBox(\ z = InputBox(\

Print \ x y z\ Print \排序前\ \ \ If x < y Then t = x: x = y: y = t If y < z Then t = y: y = z: z = t If x < y Then

t = x: x = y: y = t End If End If

Print \排序后\ \End Sub

C.4

Dim a(3) As Integer

Private Sub Command1_Click() Picture1.Cls For i = 0 To 2

a(i) = Int(Rnd * 100 + 200) Picture1.Print a(i) Next i End Sub

Private Sub Command2_Click() Picture2.Cls Dim z As Integer For i = 0 To 1

If a(i) > a(i + 1) Then z = a(i + 1) a(i + 1) = a(i) a(i) = z

\

End If Next i

Picture2.Print a(0) Picture2.Print a(1) Picture2.Print a(2) End Sub

C.5

Private Sub Text2_LostFocus() Dim m%, n%, y% m = Val(Text1) n = Val(Text2)

If n Mod 2 <> 0 Then

MsgBox (\脚数必定为偶数\ Text2 = \

Text2.SetFocus Else

y = n / 2 - m If y < 0 Then

MsgBox (\脚数必须≥2倍的头数,请重新输入\ Text2 = \

Text2.SetFocus Else

x = n / 2 - m Label2 = y Label3 = m - y End If End If End Sub

C.6

Private Sub Command1_Click() Dim a!, b!, c!, x1!, x2!, de! a = Text1 b = Text2 c = Text3

de = b * b - 4 * a * c t = 2 * a

If de = 0 Then

Text4 = Format(-b / t, \ Text5 = Format(-b / t, \ElseIf de > 0 Then

Text4 = Format((-b + Sqr(de)) / t, \ Text5 = Format((-b - Sqr(de)) / t, \

Else

Text4 = Format(-b / t, \ Text5 = Format(-b / t, \End If End Sub

Private Sub Command2_Click() Text1 = \Text2 = \Text3 = \Text4 = \Text5 = \End Sub

C.7

Private Sub Text3_LostFocus() Select Case Trim(Text3) Case \

Text4 = Val(Text1) + Val(Text2) Case \

Text4 = Val(Text1) - Val(Text2) Case \

Text4 = Val(Text1) * Val(Text2) Case \

If Val(Text2) = 0 Then

MsgBox \分母为零,重新输入\ Text2 = \

Text2.SetFocus Else

Text4 = Val(Text1) / Val(Text2) End If End Select End Sub

C.8

Private Sub Text1_LostFocus() Select Case Trim(Text1) Case 1

Text2 = \ Case 2

Text2 = \ Case 3

Text2 = \ Case 4

Text2 = \

Case 5

Text2 = \ Case 6

Text2 = \ Case 7

Text2 = \ Case Is > 7, Is < 1

MsgBox \数字为1~7,重新输入\ Text1 = \

Text1.SetFocus End Select End Sub 或者

Private Sub Text1_LostFocus() If Text1 > 7 Or Text1 < 1 Then

MsgBox \数字为1~7,重新输入\ Text1 = \

Text1.SetFocus Else

Text2 = Choose(Text1, \\End If End Sub

D.1

Private Sub Form_Click() For i = 1 To 9

Print Tab(10 - i); String(2 * i - 1, Trim(Str(i))) Next i End Sub

D.2

Private Sub Form_Click() For i = 1 To 10 Step 1

Print Tab(i); String((20 - 2 * i), Chr(64 + i)) Next i End Sub

D.3

Private Sub Command1_Click() Dim s!, t!, i& s = 1 t = 1

For i = 1 To 100000

t = t + i s = s + 1 / t

If 1 / t < 0.00001 Then Exit For Next i

Print \结构\项\End Sub

D.4

Private Sub Command1_Click() Dim n&, pi#, i&

n = InputBox(\输入n值\pi = 2

For i = 1 To n

pi = pi * (2 * i) / (2 * i - 1) * (2 * i) / (2 * i + 1) Next i

Print \当n=\时,pi=\End Sub

D.5

Private Sub Form_Click() Dim s!, t!, i!, a%, n% a = Int(Rnd * 9 + 1) n = Int(Rnd * 6 + 5) t = 0: s = 0

Print \ For i = 1 To n t = t * 10 + a s = s + t Print t; Next i Print

Print \End Sub

D.6

Private Sub Command1_Click() Dim s As Integer s = 0

For i = 1 To 9 For j = 0 To 9 For k = 0 To 9

s = i * 100 + j * 10 + k

If s = i ^ 3 + j ^ 3 + k ^ 3 Then Print s

8q0098uzgc4ddq243gyf
领取福利

微信扫码领取福利

微信扫码分享