Skip to content

Instantly share code, notes, and snippets.

@kylethedeveloper
Last active April 9, 2018 18:27
Show Gist options
  • Save kylethedeveloper/2a02d89a3ef1bbc3f4f0648716975c1a to your computer and use it in GitHub Desktop.
Save kylethedeveloper/2a02d89a3ef1bbc3f4f0648716975c1a to your computer and use it in GitHub Desktop.
Project Euler - Problem 1 - Multiples of 3 and 5
/*
Project_1.cpp : Multiples of 3 and 5
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.
*/
#include <iostream>
using namespace std;
int main()
{
int sum = 0; // initialize sum
for (int i = 0; i < 1000; i++) // below 1000
{
if (i % 3 == 0 || i % 5 == 0) // multiples of 3 or (||) 5
{
sum += i; // add the number to the sum
}
}
cout << "The sum is: " << sum << endl; // print sum
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment