Project Euler problem:
If we list all the natural numbers below
10
that are multiples of3 or 5
, we get3, 5, 6 and 9
What you are doing is some calculation error. You see there are some common multiples of 5 and 3 like 15,30,45... so since you are adding these in both the sums you are getting a higher value.
A slight modification to the code will do the trick.
for(x= 0; x < 1000; x += 3)
{
if(x%5)
{
a = a + x;
}
}
for(y = 0; y < 1000; y += 5)
b = b + y;
z = a + b;
printf("%lu", z);