【简答题】
Private Function IsPrime(ByVal x As Integer) As Boolean
Dim i As Integer
For i = 2 To Sqr(x)
If x Mod i = 0 Then
IsPrime = False
Exit Function
End If
Next
IsPrime = True
End Function
Private Sub Command1_Click()
'考生编写程序开始
'======================================
????
'=========================================
'考生编写程序结束
Open App.Path & "\out5.dat" For Output As #1
Print #1, Text1.Text, Label1(0).Caption, Label1(1).Caption, Label1(2).Caption
Close #1
End Sub
参考答案
Dim i As Integer
Dim n As Integer
Dim counter As Integer
Dim arr(3) As Integer
n = Val(Text1.Text)
counter = 0
For i = n - 2 To 3 Step -2
If IsPrime(i) Then
arr(counter) = i
counter = counter + 1
If counter = 3 Then
Exit For
End If
End If
Next
For i = 0 To 2
Label1(i).Caption = arr(i)
Next