multiples of 3 and 5

Warren HansenalgorithmsLeave a Comment

I like love working with algorithms.
Concept: 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.
Test: Find the sum of all the multiples of 3 or 5 below 1000.

A solution I came up with in swift to sum multiples of any Int and also have an under param to test for multiples below 1000 in this case.

Console output: The sum of the multiples of 3 below 1000 is 166833

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.