3个回答
展开全部
Sub test()
Dim i As Integer
Dim j As Integer
Dim m As Boolean
For i = 100 To 200
m = True
For j = 2 To i ^ 0.5
If i Mod j = 0 Then
m = False
Exit For
End If
Next j
If m Then Print i
Next i
End Sub
Dim i As Integer
Dim j As Integer
Dim m As Boolean
For i = 100 To 200
m = True
For j = 2 To i ^ 0.5
If i Mod j = 0 Then
m = False
Exit For
End If
Next j
If m Then Print i
Next i
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Public Sub iTest()
'求 x - y 之间的素数
Dim x, y, t As Boolean, i, j, k, res, msg$, n, tmp
x = 100 '最小值
y = 200 '最大值
For i = x To y
If i Mod 2 <> 0 Then
j = 3
k = Int(i ^ (0.5)) + 1
t = True
Do While j <= k
If i Mod j = 0 Then t = False: Exit Do
j = j + 2
Loop
If t Then res = res & " " & i
End If
Next
tmp = Split(Trim(res), " ")
n = UBound(tmp) + 1
msg = x & " - " & y & " 之间有 " & n & " 个素数:"
MsgBox msg & Chr(10) & Join(tmp, ",")
' Print msg & Chr(10) & Join(tmp, ",")
End Sub
'求 x - y 之间的素数
Dim x, y, t As Boolean, i, j, k, res, msg$, n, tmp
x = 100 '最小值
y = 200 '最大值
For i = x To y
If i Mod 2 <> 0 Then
j = 3
k = Int(i ^ (0.5)) + 1
t = True
Do While j <= k
If i Mod j = 0 Then t = False: Exit Do
j = j + 2
Loop
If t Then res = res & " " & i
End If
Next
tmp = Split(Trim(res), " ")
n = UBound(tmp) + 1
msg = x & " - " & y & " 之间有 " & n & " 个素数:"
MsgBox msg & Chr(10) & Join(tmp, ",")
' Print msg & Chr(10) & Join(tmp, ",")
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
cls
s=0
for i=3 to 200 step 2
for j=2 to int(sqr(i)
if i mod j=0
s=s+i
exit for
endif
next j
next i
print "3到200之间的所有非偶数非素数的数之和:";s
end
s=0
for i=3 to 200 step 2
for j=2 to int(sqr(i)
if i mod j=0
s=s+i
exit for
endif
next j
next i
print "3到200之间的所有非偶数非素数的数之和:";s
end
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询