diff options
author | Kai Stevenson <kai@kaistevenson.com> | 2023-03-31 23:06:23 -0700 |
---|---|---|
committer | Kai Stevenson <kai@kaistevenson.com> | 2023-03-31 23:06:23 -0700 |
commit | 506f390293f6497dbb3e38031a92e018de3403f8 (patch) | |
tree | d7f6192354415d1b2e6c04e232ef407294e0fa17 /problem1/problem1.c |
Diffstat (limited to 'problem1/problem1.c')
-rw-r--r-- | problem1/problem1.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/problem1/problem1.c b/problem1/problem1.c new file mode 100644 index 0000000..a2aad3d --- /dev/null +++ b/problem1/problem1.c @@ -0,0 +1,14 @@ +/* + 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. */ + +#include <stdio.h> + +int main() { + unsigned int sum; + for (int i = 1; i < 1000; i++) { + if (i % 3 == 0 || i % 5 == 0) { + sum += i; + } + } + printf("%u\n", sum); +} |