大学生心理咨询记录表:asp程序 求1-100内所有质数

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/04 16:45:05

楼上的错了

<%
for i=1 to 100 step 2
if i<=3 then response.Write(i&"<BR>")
if i>3 then
chk=false
for j=2 to (i / 2)
if i mod j=0 then chk=true
next
if not chk then response.Write(i&"<BR>")
end if
next
%>

<%
For i = 1 To 100
k = 1
For j = 2 To i / 2
If i Mod j = 0 Then k = 0
Next j
If k = 1 Then Response.Write i
Next i
%>

step 2以后,2就没了

<%
for i=2 to 100
k=0
for j=2 to (i-1)
if i mod j=0 then
k=k+1
end if
next
if k=0 then
response.Write(i&"<br>")
end if
next
%>

结果:2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

共25个

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 51 53 56 57 59 61 67 83 87 89 97

对啊,2也是质数啊。