Skip to content

Instantly share code, notes, and snippets.

@pohatu
Created April 14, 2014 07:46
Show Gist options
  • Save pohatu/10625174 to your computer and use it in GitHub Desktop.
Save pohatu/10625174 to your computer and use it in GitHub Desktop.
fizzbuzz in one loop in C (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));
switch (db){
case (1):
printf("fizz\n"); //01
break;
case (2):
printf("buzz\n"); //10
break;
case (3):
printf("fizzbuzz\n"); //11
break;
default: //00
printf("%d\n",i);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment