Last active
May 19, 2016 23:40
-
-
Save TwiN/34b8c4451e579364d720055c1e629991 to your computer and use it in GitHub Desktop.
my version of fizzbuzz in C++
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 "stdafx.h" | |
#include "iostream" | |
using namespace std; | |
int main() | |
{ | |
for (int i = 0; i < 101; i++) { | |
if (i % 3 == 0 ^ i % 5 == 0) { // can't be both | |
cout << (i % 3 == 0 ? "fizz" : "buzz") << endl; | |
} else if (i % 3 == 0) { // if got here, then fizzbuzz because above XOR | |
cout << "fizzbuzz" << endl; | |
} else { // neither fizz or buzz | |
cout << i << endl; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment