Created
April 14, 2014 07:46
-
-
Save pohatu/10625174 to your computer and use it in GitHub Desktop.
fizzbuzz in one loop in C (bit-wise OR trick)
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 <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