My plan is to post a solution to all the ProjectEuler.net problems I have managed to solve. But don’t worry I won’t spoil your fun throwing out the answer right away. Instead I’ll describe my reasoning and paste my code, so that you can work on your own solution.
Problem 1 has the following description:
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.
Probably the easiest problem on the site. Simply use mod and traverse the numbers.
int main(){
int i, j, sum = 0;
for (i=1;i<1000;i++){
if (i%3==0 || i%5==0)
sum+=i;
}
printf("%dn",sum);
return 0;
}
The next ones will be more interesting, so stay tuned.
your solution is probably wrong..time limit.