vb计算1到1000之间既能被3整除,又能被7整除的个数,以及这些数的和?

2024-11-04 08:46:11
推荐回答(3个)
回答1:

Private Sub Command1_Click()
    Dim i As Integer, sum As Integer, n As Integer
    n = 0: sum = 0
    For i = 1 To 1000
        If i Mod 3 = 0 And i Mod 7 = 0 Then
            sum = sum + i
            n = n + 1
        End If
    Next i
    
    Print "1到1000之间既能被3整除,又能被7整除的个数是:" & n & "个 ,这些数的和是:" & sum
End Sub

回答2:

<%
Dim t,s,r,l't是除3的余数,s是除以7的余数,r是可以整除3和7的数的和,l每十个数就换了
for i=1 to 1000 step 1
t = i mod 3
s = i mod 7
l = i mod 10
if t=0 and s=0 then
l = l+1
if (l mod 10)=0 then
response.write "
"
end if
response.write i&" "
r=r+i
end if

Next
response.write "
r="&r

%>

回答3:

Private Sub Command1_Click()
For i = 1 To 1000
If i Mod 3 = 0 Then s = s + 1
If i Mod 7 = 0 Then n = n + 1
Next i
Print "被3除= " & s
Print "被7除= " & n
End Sub