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.
1
| #include <iostream> ; |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
| int main ()
{
int res = 0;
int max = 1000;
int multipleOfThree;
int multipleOfFive;
for (int i=1; 3*i < max; i++)
{
multipleOfThree=3*i;
multipleOfFive=5*i;
if (multipleOfThree >= 1000)
multipleOfThree=0;
if (multipleOfFive >= 1000)
multipleOfFive=0;
if(multipleOfThree%5==0)
multipleOfThree=0;
res += multipleOfThree+multipleOfFive;
}
cout << "resultatet er ";
cout << res;
return 0;
} |
0 Responses to “Project Euler - Problem 001”
Leave a Response