请人编VB中的程序

来源:百度知道 编辑:UC知道 时间:2024/05/10 07:46:59
求一个输入一个数确定那个是不是素数的程序
怎样在窗体上+那个啊?

窗体上加一个commandbutton
Private Sub Command1_Click()
Dim f As Boolean
f = True
a = InputBox(输入一个数, 判断素数)
For i = 2 To Int(Sqr(a) + 1)
If a Mod i = 0 Then
f = False
Exit For
End If
Next i

If a = 2 Then
f = True
End If

If f = True Then
MsgBox "是素数"
Else
MsgBox "不是素数"
End If
End Sub

界面自已看着办。
sub ***_click(~~~~~~~~~~~~~~
a%
msgbox("输入整数a")
if(a/???什么叫素数忘了,不知道除几等于O))
putbox(“是素数”)
end if
end sub

太……
最笨的方法是:
用循环,尽除。

没有这么麻烦吧。感觉弄复杂了呢。

我改改!不好意思!
窗体上加一个commandbutton
Private Sub Command1_Click()
Dim f_state As Boolean
f_state = True
a = InputBox(输入一个数, 判断素数)
if a=2 then
f_state =true
else
For i = 2 To Int(Sqr(a) + 1)
If a Mod i = 0 Then
f_state = False
End If
Next i
En