vb求出1到100之间3和7的倍数来,分别计算出它们数值得和,并输出。

2024-12-31 13:38:16
推荐回答(2个)
回答1:

dim a as integer ,b as integer
dim sa as integer, sb as integer
dim na as string, nb as string
for i = 1 to 100
if i mod 3 =0 then
na= na & cstr(i) & " "
sa=sa+i
elseif i mod 7 =0 then
nb= nb & cstr(i) & " "
sb=sb+i
endif
next
print na
print sa
print nb
print sb

回答2:

dim s as integer,k as integer
for i=1 to 100
if i mod 3 = 0 then
s=s+i
elseif i mod 7 = 0 then
k=k+i
end if
next i
print s
print k