题库 题库

【简答题】

Private Sub Command1_Click()
    Open App.Path & "\in5.txt" For Input As #1
    'Input #1, ?        '1a%
    Input #1, a%
    Text1.Text = a%
    Close #1
End Sub

参考答案

Private Sub Command2_Click()
'考生自己编写"计算"按钮的事件过程
    n = Val(Text1.Text)
    For i = n To 2 Step -1
        l = prime(i)
        If l = True Then
            Exit For
        End If
    Next
    Text2.Text = i
End Sub
Private Sub Command3_Click()
    Open App.Path & "\out5.txt" For Output As #1
    Print #1, Text2.Text
    Close #1
End Sub
Function prime(x) As Boolean
    flag = 1
    For i = 2 To x - 1
        If x Mod i = 0 Then
            flag = 0
            Exit For
        End If
    Next
    If flag = 0 Then
        prime = flag
    Else
        prime = True
    End If
End Function

相关试题