Created
June 27, 2012 09:35
-
-
Save Krelborn/3002925 to your computer and use it in GitHub Desktop.
My C++ implementation of FizzBuzz. Trying to be as simple and readable as possible.
This file contains hidden or 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
#include <iostream> | |
using std::cout; | |
using std::endl; | |
int main(int argc, const char * argv[]) | |
{ | |
for (int i = 1; i <= 100; i++) | |
{ | |
bool isDivisibleBy3 = ((i % 3) == 0); | |
bool isDivisibleBy5 = ((i % 5) == 0); | |
if (isDivisibleBy3 && isDivisibleBy5) | |
{ | |
cout << "FizzBuzz"; | |
} | |
else if (isDivisibleBy3) | |
{ | |
cout << "Fizz"; | |
} | |
else if (isDivisibleBy5) | |
{ | |
cout << "Buzz"; | |
} | |
else | |
{ | |
cout << i; | |
} | |
cout << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about this though...