Created
April 14, 2014 08:03
-
-
Save pohatu/10626171 to your computer and use it in GitHub Desktop.
FizzBuzz in C (one loop) bit-wise OR trick
This file contains 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)); | |
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