求vb语句:分别统计1~100中,满足3的倍数,7的倍数各有多少个?

2024-11-26 17:52:45
推荐回答(3个)
回答1:

Private Sub Command1_Click()
Dim m%, n%
For i = 1 To 100
If i Mod 3 = 0 Then m = m + 1
If i Mod 7 = 0 Then n = n + 1
Next i
Print "统计1~100中,满足3的倍数的个数是"; m
Print "统计1~100中,满足7的倍数的个数是"; n
End Sub

回答2:

dim 七倍数 as integer
dim 三倍数 as integer
for i as integer = 1 to 100
if i mod 7 = 0 then 七倍数 += 1
if i mod 3 = 0 then 三倍数 +=1
next
msgbox("七的倍数:" & 七倍数 & " 三的倍数:" & 三倍数)

回答3:

dim n3 as integer
dim n7 as integer
dim i as integer
for i=1 to 100
if i mod 3=0 then n3=n3+1
if i mod 7=0 then n7=n7+1
next i
print "3的倍数有" & n3 & "个"
print "7的倍数有" & n7 & "个"