Created
January 20, 2013 12:27
-
-
Save GaProgMan/4578262 to your computer and use it in GitHub Desktop.
One possible solution for the famous "Fizz Buzz" problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Project Name: FizzBuzz | |
* Solution Name: FizzBuzz | |
* Original creation date: 18/04/2011 | |
* Edit date: 18/01/2013 | |
* Programmer name: Jamie Taylor (aka "GaProgMan") | |
* File name: FizzBuzz.cpp | |
* | |
* Purpose of the project: | |
* This code is my solution for a common programmer | |
* test called "FizzBuzz". | |
* It is used by many who recruit programmers to see | |
* if the prospective programmer is worth hiring. | |
* More information on this problem can be found at a | |
* Coding Horror article called "Why Programmers can't | |
* Program" by Jeff Attwood, here: http://bit.ly/cakJHF | |
* The original problem can be found in the following | |
*comment block. | |
* | |
* Problem Discussion: | |
* Write a program that prints the numbers from 1 to | |
* 100. But for multiples of three print "Fizz" instead | |
* of the number and for the multiples of five print | |
* "Buzz". For numbers which are multiples of both | |
* three and five print "FizzBuzz". | |
* | |
* 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 <stdio.h> | |
using namespace std; | |
int main () { | |
for ( int i = 1; i <= 100; i++ ) { | |
if ( ( i % 3 == 0 ) && ( i % 5 == 0 ) ) | |
cout << "FizzBuzz" << endl; | |
else if (i % 5 == 0) | |
cout << "Buzz" endl; | |
else if (i % 3 == 0) | |
cout << "Fizz" << endl; | |
else | |
cout << i << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment