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.
1
Expert's answer
2013-02-12T10:29:30-0500
#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(); }
Comments
Leave a comment