编程 1000内能被3和7整除的数之和 不知道什么语言详情有开头已经写好了是public sub program1()

来源:学生作业学帮网 编辑:学帮网 时间:2024/03/29 23:07:30

编程 1000内能被3和7整除的数之和 不知道什么语言详情有
开头已经写好了
是public sub program1()

能被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 sub