Skip to content

Instantly share code, notes, and snippets.

@TwiN
Last active May 19, 2016 23:40
Show Gist options
  • Save TwiN/34b8c4451e579364d720055c1e629991 to your computer and use it in GitHub Desktop.
Save TwiN/34b8c4451e579364d720055c1e629991 to your computer and use it in GitHub Desktop.
my version of fizzbuzz in C++
#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