> 数学 >
编写程序,判断大于2的整数是否为质数!whlie 和 DO
人气:456 ℃ 时间:2020-09-02 04:20:35
解答
VB程序:
Private Sub CommandButton1_Click()
do
n = InputBox("请输入一个大于1的正整数","数据输入")
if n>2 then exit do
loop
i = 2
Do
r = n Mod i
i = i + 1
If r = 0 Then
MsgBox (Str(n) + "是质数")
exit sub
end if
if i>=n^0.5 then exit do
Loop
MsgBox (Str(n) + "不是质数")
End Sub
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版