VB编程 输出3到100之间所有素数
答案:3 悬赏:30 手机版
解决时间 2021-03-25 05:58
- 提问者网友:树红树绿
- 2021-03-24 14:41
VB编程 输出3到100之间所有素数
最佳答案
- 五星知识达人网友:独行浪子会拥风
- 2021-03-24 15:44
dim i,j,x
for i=3 to 100
x=1
for j=2 to i-1
if i mod j=0 then x=0
next j
if x=1 then print i
next i
for i=3 to 100
x=1
for j=2 to i-1
if i mod j=0 then x=0
next j
if x=1 then print i
next i
全部回答
- 1楼网友:从此江山别
- 2021-03-24 17:39
Private Sub Command1_Click()
Cls
For i = 2 To 100
j = i \ 2
Do While j >= 2
If i Mod j = 0 Then Exit Do
j = j - 1
Loop
If j = 1 Then Print i
Next i
End Sub
Cls
For i = 2 To 100
j = i \ 2
Do While j >= 2
If i Mod j = 0 Then Exit Do
j = j - 1
Loop
If j = 1 Then Print i
Next i
End Sub
- 2楼网友:十年萤火照君眠
- 2021-03-24 16:03
Private Sub Command2_Click()
For i = 1 To 100
If prime(i) Then Print i
Next
End SubPublic Function prime(ByVal m As Integer) As Boolean '鍒ゆ柇m鏄?惁涓虹礌鏁?
Dim b As Boolean
Dim i As Integer
b = True
For i = 2 To Sqr(m)
If m Mod i = 0 Then
b = False
Exit For
End If
Next i
prime = b
End Function
For i = 1 To 100
If prime(i) Then Print i
Next
End SubPublic Function prime(ByVal m As Integer) As Boolean '鍒ゆ柇m鏄?惁涓虹礌鏁?
Dim b As Boolean
Dim i As Integer
b = True
For i = 2 To Sqr(m)
If m Mod i = 0 Then
b = False
Exit For
End If
Next i
prime = b
End Function
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯