麻烦帮忙做下列vb题:1.编写一个判断素数的函数;并在单选按钮的单击事件过程中,用inputbox输入数据,再调

1个回答

  • 第一题答案:

    Option Explicit

    Private Sub Command1_Click()

    Dim n As Integer

    n = Val(InputBox("请输入一个数"))

    If isprime(n) Then

    Print n; "是素数"

    Else

    Print n; "不是素数"

    End If

    End Sub

    Private Function isprime(m As Integer) As Boolean

    Dim i As Integer

    isprime = True

    For i = 2 To Sqr(m)

    If m Mod i = 0 Then

    isprime = False

    Exit For

    End If

    Next i

    End Function