Skip to content

Instantly share code, notes, and snippets.

@pohatu
Created April 14, 2014 08:03
Show Gist options
  • Save pohatu/10626171 to your computer and use it in GitHub Desktop.
Save pohatu/10626171 to your computer and use it in GitHub Desktop.
FizzBuzz in C (one loop) bit-wise OR trick
#include <stdio.h>
#include <string.h>
int main() {
int i=0;
for (i=1; i<101; i++){
int db = 0;
db = db ^ 1 * (!(i%3)) ^ 2*(!(i%5));
if (db&1){printf("fizz");} //db=01 or 11
if (db&2){printf("buzz");} //db=10 or 11
if (!db){printf("%d",i);} //db=00
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment