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.
Running time: Unknown
Assessment: First code I’d written in 7-8 years. I hadn’t started measuring execution time yet, so I’m not sure how long it took to run, but it’s basically instantaneous.
#include <iostream>
using namespace std;
int main()
{
int total = 0;
for (int i = 0; i < 1000; i++)
{
if( (i % 3 == 0) || (i % 5 == 0) )
total += i;
}
cout << total;
return 0;
}
Wrong answer…………
Incorrect.