五笔打字通主页
阅读程序,写出执行结果。---- 第五章 选择分支与循环 答案 新编Visual Basic程序设计教程 陈斌 著
1. 阅读程序,写出执行结果。
(1):-------------------------------------------------------------------------------
Private Sub Form_Click()
Dim a As Integer, b As Integer
a = 1: b = 0
Do While a <= 5
b = b + a * a
a = a + 1
Loop
Print a, b
End Sub
运行结果为: 6 55
(2):-------------------------------------------------------------------------------
Private Sub Form_Click()
Dim ch As String, i As Integer
ch = "DEF"
For i = 1 To Len(ch)
ch = Mid(ch, 2 * i - 1, 1) & Left(ch, Len(ch))
Print ch
Next i
End Sub
运行结果为:
DDEF
EDDEF
FEDDEF
(3):---------------------------------------------------------------------------------
Private Sub Form_Click()
Dim p As Integer, i As Integer
p = 1
For i = 1 To 5
p = p + (2 * i - 1) / (2 * i + 1)
If p >= 20 Then Exit For
Next i
Print i, p
End Sub
运行结果为: 6 5
(4):---------------------------------------------------------------------------------
Private Sub Form_Click()
Dim p As Integer, i As Integer, n As Integer
p = 2: n = 20
For i = 1 To n Step p
p = p + 2
n = n - 3
i = i + 1
If p >= 10 Then Exit For
Next i
Print i, p, n
End Sub
运行结果为: 11 10 8
来源:济亨网
本文链接:http://wb86.com/post/154.html