在小于100的正整数中共有多少个数能被3整除?这些数字的和是?
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/08 03:38:30
在小于100的正整数中共有多少个数能被3整除?这些数字的和是?
在小于100的正整数中共有多少个数能被3整除?这些数字的和是?
在小于100的正整数中共有多少个数能被3整除?这些数字的和是?
100÷3=33……1
也就是说,100以内的正整数中能被3整除的数共33个,它们的和:
S=3+6+9+12+……+96+99
=3×(1+2+3+……+32+33)
=3×(1+33)×33÷2
=3×17×33=1683
Private Sub Form_Load()
Dim i As Integer
Dim n As Integer
Dim a() As Integer
Dim s As Integer
n = 0
For i = 1 To 100
If i Mod 3 = 0 Then
ReDim Preserve a(n)
...
全部展开
Private Sub Form_Load()
Dim i As Integer
Dim n As Integer
Dim a() As Integer
Dim s As Integer
n = 0
For i = 1 To 100
If i Mod 3 = 0 Then
ReDim Preserve a(n)
a(n) = i
n = n + 1
End If
Next i
Print "共有" & n & "个数字能被3整除:"
For i = 0 To n - 1
Print a(i)
s = s + a(i)
Next i
Print "所有数字之和=" & s
End Sub
答案是1683
收起
一楼回答正确,
二楼的太有才了,
三楼我补充修正
Sub Load3()
Dim i As Integer
Dim n As Integer
Dim s As Integer
For i = 1 To 100
If i Mod 3 = 0 Then
s = s + i
n = n + 1
全部展开
一楼回答正确,
二楼的太有才了,
三楼我补充修正
Sub Load3()
Dim i As Integer
Dim n As Integer
Dim s As Integer
For i = 1 To 100
If i Mod 3 = 0 Then
s = s + i
n = n + 1
End If
Next i
MsgBox "共有" & n & "个数字能被3整除,他们的和是" & s
End Sub
收起