Question #24157

Q2: 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.

Write an algorithm to Find the sum of all the multiples of 3 or 5 below 1000.

Expert's answer

#include <conio.h>
#include <iostream>

using namespace std;

void main()
{
long sum = 0;
for (int number = 3; number < 1000; number++)
if ((number % 3 == 0) || (number % 5 == 0))
sum += number;
cout << "The sum of the multiples of 3 or 5 below 1000 is: " << sum << endl;
_getch();
}
LATEST TUTORIALS
APPROVED BY CLIENTS