If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
Find the sum of all the multiples of 3 or 5 below 1000.
My Solution;
Sub Euler1()
Dim a, b, c
Dim SumA, SumB, SumC
Dim Count, I
a = 3
b = 5
c = 15
Count = 999
For I = a To Count Step a
SumA = SumA + I
Next
For I = b To Count Step b
SumB = SumB + I
Next
For I = c To Count Step c
SumC = SumC + I
Next
MsgBox (SumA + SumB - SumC)
End Sub
Dim a, b, c
Dim SumA, SumB, SumC
Dim Count, I
a = 3
b = 5
c = 15
Count = 999
For I = a To Count Step a
SumA = SumA + I
Next
For I = b To Count Step b
SumB = SumB + I
Next
For I = c To Count Step c
SumC = SumC + I
Next
MsgBox (SumA + SumB - SumC)
End Sub
댓글 없음:
댓글 쓰기