Skip to content

Instantly share code, notes, and snippets.

@GaProgMan
Created January 20, 2013 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GaProgMan/4578311 to your computer and use it in GitHub Desktop.
Save GaProgMan/4578311 to your computer and use it in GitHub Desktop.
One possible solution for problem 1 on the Project Euler website
/*
* Project Name: Problem One
* Solution Name: Problem One
* Original creation date: 03/07/2011
* Edit date: 18/01/2013
* Programmer name: Jamie Taylor (aka "GaProgMan")
* File name: ProblemOne.cpp
*
* Purpose of the project:
* This code is my solution for "Problem One" listed on
* Project Euler. It is based on my version of the classic
* "FizzBuzz" problem - more on which can be found at a
* Coding Horror article called "Why Programmers can't
* Program" by Jeff Attwood, here: http://bit.ly/cakJHF
* For my solution to the "FizzBuzz" problem, you can
* read my blog entry here:
* http://wp.me/s19MGD-fizzbuzz - "FizzBuzz" by Jamie Taylor
* The original problem is listed in the comment block below
*
* Problem Discussion:
* Problem One, from Project Euler. URL:
* http://projecteuler.net/index.php?section=problems&id=1
* 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.
*
* GNU Copyright information
* Copyright 2011 Jamie Taylor <jamie@taylorj.org.uk>
*
* This program is free software; you can redistribute
* it and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General
* Public License along with this program; if not, write
* to the Free Software Foundation, Inc., 51 Franklin
* Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <iostream>
using namespace std;
int main () {
int sum = 0;
for ( int i = 1; i <= 999; i++ ) {
if ( i % 3 == 0 ) {
sum += i;
}
else if (i % 5 == 0){
sum += i;
}
}
cout << "\The total of all multiples of 3 or 5 below 1000 is " << sum << endl;
char ch;
cin >> ch;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment