读书人

简单的判断素数如何会错? 帮忙看看

发布时间: 2012-03-04 11:13:33 作者: rapoo

简单的判断素数怎么会错? 帮忙看看
n=val(thisform.text1.value)
for i=2 to n-1
if n%i=0
thisform.label2.caption= "不是素数 "
else
thisform.label2.caption= "是素数 "
endif
endfor


[解决办法]
n=val(thisform.text1.value)
a= "b是素数 "
for i=2 to n-1
if mod(n,i)=0
a= "是素数 "
exit
else
loop
endif
endfor
thisform.label2.caption=a

读书人网 >VFP

热点推荐