编程 1000内能被3和7整除的数之和 不知道什么语言详情有

问题描述:

编程 1000内能被3和7整除的数之和 不知道什么语言详情有
开头已经写好了
是public sub program1()
1个回答 分类:综合 2014-10-26

问题解答:

我来补答
能被3或者7整除
public sub program1()
dim i as integer,counts as long
for i=1 to 1000
if i mod 3 =0 or i mod 7=0 then
counts=counts+i
end if
next
debug.print counts
end sub
能被3和7同时整除
public sub program1()
dim i as integer,counts as long
for i=1 to 1000
if i mod 3 =0 and i mod 7=0 then
counts=counts+i
end if
next
debug.print counts
end sub
或者因为3,7都是素数(质数),所以能同时给他们整除的数是21的倍数
public sub program1()
dim i as integer,counts as long
for i=1 to 1000
if i mod 21 =0 then
counts=counts+i
end if
next
debug.print counts
end su
 
 
展开全文阅读
剩余:2000
下一页:奇偶性的应用。