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. |
|
|
|
|
Jan 29, 2014 at 7:30pm JLBorges (4075) How many times are you adding 15 to counter2? Once or twice? What about 30, 45 ... ? Report |
Jan 30, 2014 at 2:53am LearningTheKingsOfTrades (23) You could simplify your code a good deal using the % operation (modular division) and the 'or' logical operator. http://www.cplusplus.com/doc/tutorial/operators/ It would also fix your issue, which JLBorges already covered. Last edited on Jan 30, 2014 at 2:55am Report |
|
|
Find the sum of all the multiples of 3 or 5 below 1000. |
if((number % 3 == 0) || (number % 5 == 0))
|
|
|
|
num=0
should be num=1
and that means the code can be simplified, there is no need to put && (num>=first)
.
natural numbers |