间谍生存手册:请大家教我种VB中判断素数的方法

来源:百度文库 编辑:神马品牌网 时间:2024/05/06 11:43:03

function pri(n)
pri=true
for i = 2 to int(sqr(n))
if n mod i =0 then '除以2到这个数字的平方根,如果都不整除,就是素数了
pri=false
exit for
end if
next
end function

楼上专家的基本思路没问题的!

可是n=0,1,2来?n<0的时候又如何啊???

呵呵!