vb计算1到1000之间既能被3整除,又能被7整除的个数,以及这些数的和?
展开全部
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
展开全部
<%
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 "<br/>"
end if
response.write i&" "
r=r+i
end if
Next
response.write "<br/>r="&r
%>
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 "<br/>"
end if
response.write i&" "
r=r+i
end if
Next
response.write "<br/>r="&r
%>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询