Dim i As Integer
Print \满足条件的数有:\For i = 1 To 100 If (6) Then Print i End If Next i 图5 End Sub
Function shuju(ByVal x As Integer) As Boolean Dim y As Integer shuju = False (7)
If y = 6 And x Mod 3 = 0 Then (8) End If
End Function
12.下列程序的功能是判断一个正整数是否符合要求。要求是:该数为一个奇数,并且当该数从低位到高位依次去掉一位数后剩下的数仍然是奇数。并且用MsgBox给出此数是否满足条件的提示。例如输入奇数1337,因为133、13、1都是奇数,所以弹出“1337是满足条件的数”。程序运行参考界面如图6和图7所示。 Private Sub Form_Click()
Dim i As Integer, flag As Boolean i = Val(Text1.Text)
(9) If flag = True Then
MsgBox i & \是满足条件的数\
图6 Else
MsgBox i & \不是满足条件的数\
End If End Sub
Private Sub superodd( (10) , f As Boolean) Dim p As Integer f = True
Do While n > 0
If (11) Then n = n \\ 10 Else
f = False Exit Sub End If Loop
图7
21
End Sub
13.下列程序的功能是:随机生成10个三位正整数,存放到数组a中,再用选择排序法对数组a从大到小排序,并且把排好顺序的数组元素写入D盘的根目录下的file1.txt文件中。程序运行参考界面如图8。 Private Sub Form_Click()
Dim n As Integer, a(1 to 10) As Integer, i As Integer Dim j As Integer, imax As Integer, t As Integer Print \排序前\For i = 1 To 10 (12) Print a(i); Next i
Print \排序后\
For i = 1 To 9 imax = i
For j = i + 1 To 10
If (13) Then imax = j Next j t = a(i)
a(i) = a(imax) a(imax) = t Next i
(14) For i = 1 To 10 (15) Next i Close #1
Print \文件已经建立\End Sub
图8 22