VB题目!非常感谢

来源:百度知道 编辑:UC知道 时间:2024/06/15 21:41:08
在2-100的数中,先去掉2的倍数(不包括2),再去掉3的倍数(不包括3),再再去掉4的倍数,类似地,直到100。则剩下的数都是质数。试用程序求出2-100间的所有质数。
我没学过VB,别人让帮忙的!

dim a(100) as integer
dim i as integer,j as integer
a(1)=-1 '以下是查找质数,把1-100中不是质数的数字都换成-1
for i=1 to 100
if a(i)<>-1 then
for j=i+1 to 100
if a(j) mod a(i)=0 then
a(j)=-1
end if
next
print "1-100中的质数:" '以下是打印1-00中所有的质数
j=0
for i=1 to 100
if a(i)<>-1 then
j=j+1
if j mod 10 then print
print j;
end if
next
print
print "共有";j;"个"

dim i as integer
dim j as integer
dim zhishu as boolean
for i=3 to 100
zhishu = true
for j= 2 to sqr(i)
if i mod j =0 then
zhishu=false
exit for
endif
next j
if zhishu = true then print i
next i

for i=kaishishu to jieshushu
a=0
for o=1 to i
dim p
p=i/o
p=p+""
p=cstr(p)
if Instr(p,".")=0 then
a=a+cint(p)
end if
next
respons